川大上课时间:ASP.NET的DataGrid如何实现通用的排序和自定义列?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/06 13:23:15

自定义列
选择datagrid的属性AutoGenerateColumns 将其设置为false
然后再框架编辑那里写<columns><asp:templatecolumns><itemtemplate>
数据绑定我用databinder
<%# DataBinder.Eval(Container.DataItem,"columnname")%>
</itemtemplate></asp:templatecolumns></columns>

sort 也是用属性AllowSorting 将其设置为true
在其sortcommand事件里写
DataView dv = new DataView(dt);

// The DataView provides an easy way to sort. Simply set the Sort property with
// the name of the field to sort by.
dv.Sort = e.SortExpression; // sortexpression