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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

here is a link that might help you out
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.