In my gridview I have 6 pages. When I go to page two and try to sort by descending on any of my columns I get sent back to page 1. Is there a way to stay at page two?
+1
A:
You'll need to assign the current PageIndex
property of the GridView in your sorting method after the sort but before the DataBind.
David Neale
2010-05-05 09:31:28
It doesn't work because its sending me back to page 1
Jeff
2010-05-05 10:28:58
Are you setting the **PageIndex** of your gridview in your **sorting method** as david suggests? Did you find another solution?
senloe
2010-05-25 17:09:03
A:
In PageIndexChanging
event, you need to set the page and rebind your data. For instance like following:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();//a method that re/sets the datasource
}
Check this article.
KMan
2010-05-05 09:34:00
Did you turn on the Paging? `AllowPaging="True"` and `PageSize="10"`. Also on page load I believe you have something like this `if (!IsPostBack) bindGridView();`
KMan
2010-05-05 10:35:11
Did you turn on the Paging? YesAllowPaging="True" Yes and PageSize="10" Yes. Also on page load I believe you have something like this if (!IsPostBack) bindGridView(); I just tried that and it didnt work.The problem is not paging and sorting. The problem is staying on page 2 for example after the sort is done??
Jeff
2010-05-05 10:42:24
@Jeff: For that matter, see Tim's response. One workaround could, save the currentPageNo in `ViewState`, as soon as the Sort is done, manually set the `GridView1.PageIndex` to currentPageNo and reset datasource.
KMan
2010-05-05 11:29:11