怎么在datagrid排序根据某个字段!急!

nedvedlh 2003-07-30 06:52:42
在先等待 !
...全文
77 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
好运 2003-08-11
  • 打赏
  • 举报
回复
hehe
诸葛神侯 2003-08-10
  • 打赏
  • 举报
回复
private void ClueDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
try
{
this.cusService=new Exhibit.ExWebApp.CustomerService.CustomerService();
DataSet ds=this.cusService.GetCustomerDataSet();

DataView dv=ds.Tables["T014"].DefaultView;

this.ClueDataGrid.DataSource=dv;
dv.Sort=e.SortExpression;

this.ClueDataGrid.DataBind();

}
catch(System.Exception ex)
{
throw(ex);
}
}
nedvedlh 2003-07-31
  • 打赏
  • 举报
回复
谢谢大家,一时头昏!只要点击那个字段的标题就可以那个列排序!简单但实用!谢谢!
好运 2003-07-31
  • 打赏
  • 举报
回复
up
happyno7 2003-07-30
  • 打赏
  • 举报
回复
Private Sub DG_ContentList_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DG_ContentList.SortCommand
'排序
If Me.ViewState.Item("SortType") Is Nothing Then
Me.DataView.Sort = e.SortExpression
Me.ViewState.Item("SortType") = " desc"
Else
Me.DataView.Sort = e.SortExpression.ToString & Me.ViewState.Item("SortType")
If Me.ViewState.Item("SortType") = "" Then
Me.ViewState.Item("SortType") = " desc"
Else
Me.ViewState.Item("SortType") = ""
End If
End If
Me.DG_ContentList.DataBind()

End sub
lijiangchxp 2003-07-30
  • 打赏
  • 举报
回复
使用 DataView 的Sort 排序,再将DataView 绑定到datagrid 的DataSouse 上就可以了
zhangzs8896 2003-07-30
  • 打赏
  • 举报
回复
同意楼上!
雪狼1234567 2003-07-30
  • 打赏
  • 举报
回复
你只要点击那个字段的标题就可以以那个列排序,
如果你想用代码控制,那么使用DataView里的Sort
private void SortByTwoColumns()
{
// Get the DefaultViewManager of a DataTable.
DataView myDataView = DataTable1.DefaultView;
// By default, the first column sorted ascending.
myDataView.Sort = "State, ZipCode DESC";
}

111,077

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧