Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HOW TO SORT the DATA in Gridview by clicking header cloumn of gridview
=====================================================

Dear Friends,

I have a Gridview with thousand of records displayed in it.

am sorting data by clicking header columns of gridview. also i gave allow sorting to TRUE.

in the first page of gridview it is sorting, so when i click on paging it doesnot sort in another page (for this again i need to click on header column)

so i dont want to click header for ever page. once i click on first header , it must sort for every page.

Please help.
Posted

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[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900