How to tell what column GridView is sorted on?
Hi Everyone,
I have a gridview control connected to a sqldatasource control. I am allowing the user to sort the columns in the gridview control. The user can click a row and visit another page. When they return I need to set the column sort again. I have seen that I can use the Sorting event to set the sort order of the data when I return to the page in the Sorting event. But before I leave the page where can i get the column it is currently sorted on along with the direction?
Thanks!
Re: How to tell what column GridView is sorted on?
Hey,
In the Sorting event of the GridView, you should be able to use the SortExpression property of the GridViewSortEventArgs parameter to get information about which column is being sorted on. You could store this into a Session Variable, or somewhere similar, and then retrieve it when you come back to the page.
http://msdn.microsoft.com/en-us/libr...eventargs.aspx
Hope that helps!
Gary
Re: How to tell what column GridView is sorted on?
Thanks. I can store it in a session variable. When I return to the page, I can't set a sort on the SQLDataSource control (connected to AS400). So would I put the data in somelike a dataview grid, sort it and then set the datasource of the gridview to the datavieew grid? Or is there a much better method to do this?
Re: How to tell what column GridView is sorted on?
Hello,
I haven't tried this, but, am I not right in saying that there is a SortExpression on the GridView itself? Can you not set this when you return to the page, which should in turn then tell the SqlDataSource what data to return.
Gary