Gridview 排序问题
我有一个 gridview,并且在其中使用分页
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindData();
}
现在的问题是,当我单击标题对 gridview 进行排序,然后转到第二页,然后返回第一页时,它不记得排序表达式降序或升序。
无论我点击的页面索引如何,如何保持排序的方向?
谢谢
I have a gridview and i am using paging in it
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindData();
}
Now the problem is that when I click on a header to sort the gridview and then I go to the second page, then come back to the first one, it is not remembering the sort expression DESC or ASC.
How can i persist the direction in which it is being sorted no matter on the page index i click on?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ViewState 存储 SortDirection,如此处或此处。
如果您的
BindData
方法还加载了应有的数据源,则您需要按此 SortDirection 对数据源进行排序。更改BindData
以便它采用 SortDirection 和 PageIndex 作为参数。例如:
然后对 Grid 的 DataSource 进行排序并相应地设置其 PageIndex。
Use ViewState to store the SortDirection like here or here.
If your
BindData
method also loads the DataSource what it should, you need to sort your datasource by this SortDirection. ChangeBindData
so that it takes the SortDirection and PageIndex as parameters.For example:
Then sort the Grid's DataSource and set it's PageIndex there accordingly.