sorting and paging with gridview asp.net

前端 未结 5 1352
日久生厌
日久生厌 2020-11-27 03:15

I\'m trying to get a gridview to sort and page manually with no success.

The problem is that when a user clicks the column they want to sort, it sorts that page, but

5条回答
  •  渐次进展
    2020-11-27 03:31

    Tarkus's answer works well. However, I would suggest replacing VIEWSTATE with SESSION.

    The current page's VIEWSTATE only works while the current page posts back to itself and is gone once the user is redirected away to another page. SESSION persists the sort order on more than just the current page's post-back. It persists it across the entire duration of the session. This means that the user can surf around to other pages, and when he comes back to the given page, the sort order he last used still remains. This is usually more convenient.

    There are other methods, too, such as persisting user profiles.

    I recommend this article for a very good explanation of ViewState and how it works with a web page's life cycle: https://msdn.microsoft.com/en-us/library/ms972976.aspx

    To understand the difference between VIEWSTATE, SESSION and other ways of persisting variables, I recommend this article: https://msdn.microsoft.com/en-us/library/75x4ha6s.aspx

提交回复
热议问题