grid view sorting retain sort order and sort expression

i would like to retain the sort expression and the sort order everytime the gridview loads.
please help
eagle_eaAsked:
Who is Participating?
 
donjon56Commented:
Yes, you do need to store the Sort Expression and Sort Direction.

I would suggest you use ViewState instead of Session.

I typically use the ViewState beacuse it is not stored on the server (stored in viewstate hidden variable in the form) and it is scoped to this page only.

Session variable could be lost between page submits for various reasons (IIS reset, etc).  If you do not name the session key uniquely it could be overwritten from another data grid.
0
 
xav056Commented:
you need to store the .SortDirection.ToString in a session variable
and set it after each load
the gridview has a sorted event I think
In that do Session("SortDirection")=gridview.SortDirection

Then when you load the information do
GridView.SortDirection=Session("SortDirection")

here is a link that might help you out
http://stackoverflow.com/questions/6083418/how-to-keep-gridviews-sorting-state-ascending-descending
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.