通过单击标题列在Gridview中对数据进行排序 [英] Sorting data in Gridview by clicking on header column

查看:63
本文介绍了通过单击标题列在Gridview中对数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过单击gridview的标题表头来对Gridview中的数据进行排序
================================================== ===

尊敬的朋友,

我有一个Gridview,其中显示了成千上万条记录.

通过单击gridview的标题列对数据进行排序.我也给了允许排序为TRUE.

在gridview的第一页中,它正在排序,因此当我单击分页时,它不会在另一页中排序(为此,我再次需要单击标题列)

所以我不想点击任何页面的标题.一旦我单击第一个标题,它就必须对每个页面进行排序.

请帮忙.

解决方案

,这样您就可以进行了.
1)将SortExpression添加到GridView模板,并在gridview属性中设置Allow Sorting = True
2)创建on函数,该函数将为您提供排序表达式并将其存储在您的视图状态或根据您的要求的任何其他内容中.除了可以保持排序方向外,还可以使用视图状态或其他方式来维护它.
3)因此,在绑定网格时,您可以将该视图状态值用于排序表达式以及排序方向.
4)因此,当您触发下拉菜单选择的索引更改以按学生姓名排序时,还要将排序表达式的视图状态值设置为学生姓名,并将排序方向设置为< code> asc</code>.或< code> desc</code>.
5)当您要更改页面索引时,请使用先前存储的排序表达式和方向来对数据视图进行排序,以保持排序.

可以在直接查询中使用< code>默认视图</code>来代替按原因排序. < code>数据表</code>的并在该视图上应用Sorting,最好是进行gridview排序.

您可以参考此链接...
排序GridView 1 [排序GridView 2 [ http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx [分类和分页通用GridView [ ^ ]
用户GridView ASP.NET [ GridView分页和排序 [ 解决方案

so you can go like this.
1) Add SortExpression to GridView Template as well as set Allow Sorting = True in gridview properties
2) create on function which will give you sort expression and store it in your view state or any thing else as per your requirement. As well as it will also maintain the sort direction, you can also maintain it with view state or other way.
3) so while binding grid you can use that view state value for sort expression as well as sort direction.
4) so while you fire your dropdown selected index change for sorting by student name then also set the value of view state for sort expression as student name and sort direction as <code>asc</code> or <code>desc</code>.
5) while you are going to change your page index as that time sort your data view using previously stored sort expression and direction to maintain sorting.

Instead of using order by cause in direct query you can use <code>Default View</code> of <code>data-table</code> and apply Sorting on that view, it is better idea for gridview sorting.

you can refer this links...
Sorting GridView 1[^]

Sorting GridView 2[^]


Hi,

Refer the links below:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx[^]
Sorting and Paging of an Generic GridView[^]
Userful GridView ASP.NET[^]
GridView Paging and Sorting[^]

--Amit


这篇关于通过单击标题列在Gridview中对数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆