总结ASPxGridView的使用 - 图文 联系客服

发布时间 : 星期一 文章总结ASPxGridView的使用 - 图文更新完毕开始阅读b7bf972d3169a4517723a3e2

OnDeleting=\OnInserting=\Source1_Modifying\OnUpdating=\

SelectCommand=\* FROM [Customers]\DeleteCommand=\LETE FROM [Customers] WHERE [CustomerID] = ?\

InsertCommand=\INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\ UpdateCommand=\[Customers] SET [CompanyName] = ?, [ContactName] = ?, [City] = ?, [Region] = ?, [Country] = ? WHERE [CustomerID] = ?\

protected void AccessDataSource1_Modifying(object sender, SqlDataSourceCommandEventArgs e) {

DemoSettings.AssertNotReadOnly(); }

用代码实现

AccessDataSource ds = new AccessDataSource(); ds.DataFile = AccessDataSource1.DataFile;

ds.SelectCommand = \Photo from [Employees] where employeeid=\+ id;

DataView view = (DataView)ds.Select(DataSourceSelectArguments.Empty);

if(view.Count > 0) return view[0][0] as byte[]; return null;

ObjectDataSource

SelectMethod=\ />

SelectMethod=\UpdateMethod=\InsertMethod=\\

/>

ObjectDataSource.Parameters

ObjectDataSource 使用的类

(以下代码整理并修改至《ASP.NET 2.0 Revealed》P71-P78) (另外一个购物篮的例子,参考P138) public class Person {

private int id;

private string firstName; private string lastName;

public int Id {...}

public string FirstName {...} public string LastName {...}

public Person(int id, string firstName, string lastName) {

this.id = id;

this.firstName = firstName; this.lastName = lastName; } }

public class PersonCollection : List {} public class PersonManager {

private const string personsKey = \

public PersonCollection SelectPersons() {

HttpContext context = HttpContext.Current; if (context.Application[personKey] == null) {

PersonCollection persons = new PersonCollection(); persons.Add(new Person(0, \\ persons.Add(new Person(0, \\ persons.Add(new Person(0, \\ persons.Add(new Person(0, \\ context.Application[personKey] = persons; }

return context.Application[personKey] as PersonCollection; }

public Person SelectPerson(int id) {

foreach (Person p in SelectPersons()) if (p.Id == id) return p; return null; }

public void DeletePerson(int id) {

PersonCollection persons = (Application[personKey] as PersonCollections);

Person person = SelectPerson(id);

if (person != null)

persons.Remove(person); }

public void InsertPerson(int id, string firstName, string lastName) {

PersonCollection persons = (Application[personKey] as PersonCollections);

persons.Add(new Person(id, firstName, lastName)); }

public void UpdatePerson(int id, string firstName, string lastName) {

Person person = SelectPerson(id); if (person != null) {

person.FirstName = firstName; person.LastName = lastName; } } }

--(五) ASPxGridView 事件

--------------------------------------------------------- ASPxGridView

默认是以callback方式(ajax方式)传递数据给服务器来实现局部刷新功能的 若要改为postback方式,可设置 EnableCallBacks = \

--------------------------------------------------------- 展示视图

---------------------------------------------------------

RowCreated(创建行数据时触发,类似 GridView 的 DataItemCreate 事件) protected void grid_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e) {

if(e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;

// 设置模板列lable控件值

Label label = grid.FindRowCellTemplateControl(e.VisibleIndex, null, \hangePercent\as Label;

decimal change = (decimal)grid.GetRowValues(e.VisibleIndex, \e\