I have a GridView, with sortable headers. If I click on a header to sort accending or descending on a page other than page 1, it sorts correctly and displays the new sortable results on that page. I want to know if it’s possible to perform the sort, and then jump back to the first page, maintaining the last sort preference.
Example:
I have a list of 20 First Names & Last names. I’m currently viewing page 2, records 11-20. The list is currently sorted A-Z (Ascending). When clicking on the the First Name header to sort descending, I want the list to return Z-A, but I want the grid to jump back to page 1, displaying Z-A. How do I do this?
My binding currently looks like this:
gvBillers.DataSource = dataView;
gvBillers.DataBind();
gvBillers.PageIndex = 0;
gvBillers.HeaderRow.TableSection = TableRowSection.TableHeader;
By setting PageIndex to 0 after doing DataBind does jump back to the first page, but when clicking on the hyperlink in the grid to open that record, it opens the wrong record, so somewhere I’m going wrong…
You’ll want to set your
PageIndexbefore youDataBind: