我在.aspx上存在一个DataGrid1,该DataGrid1设为"在运行时自动生成列",我在属性中将AllowSorting设为了True,之后DataGrid1的每个列标题上加上了下划线,运行后也可以点击了,但还是没有做出排序来.该如何去实现呢?
解决方案 »
- 用vs2008做一个winform程序,连接access数据库,只能更新、插入bin目录下的数据库,不能操作主数据库文件
- 如何用程序实现PING?
- 设备编程,怎样获取当前路径?
- c#调用以前的Dll问题,请前辈帮小弟看下代码,小弟先感谢了!
- 如何用button清除picturebox中已经载入的图片...
- 新手问题:关于窗体子控件的事件传递问题
- 用C#怎么获取一个dll文件中的命名空间
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 c#中AxWindowsMediaPlayer有rate个属性吗?[
- WPF中Image控件不释放内存
- 关于c#时间类型的疑问
- arraylist中移除
- 怎样实现c#对desktop.ini文件的修改?
datatable.DefaultView.Sort=SortField;
再绑定此datatable。
简单的
Get the sort key (the value you set in the Sort expression) from the SortExpression property of the DataGridSortCommandEventArgs argument.
Sort the data.
Rebind the data from the data source.
The following example shows how to sort by handling the SortCommand event. The method gets the sort key value and uses it to set the Sort property of a DataView object. The code then rebinds the grid to the DataView object, which automatically returns the data in sorted order. ' Visual Basic
Private Sub DataGrid1_SortCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) _
Handles DataGrid1.SortCommand
DataView1.Sort = e.SortExpression
DataGrid1.DataBind()
End Sub