刘惜芬受刑原白鹭:ASP.NET的DataGrid如何实现通用的排序和自定义列?

来源:百度文库 编辑:中科新闻网 时间:2024/05/12 07:34:01

自定义列
选择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