Jeff
Jeff

Reputation: 11

Paging in Gridview

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?

Upvotes: 1

Views: 449

Answers (2)

Kamran Khan
Kamran Khan

Reputation: 9986

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.

Upvotes: 0

David Neale
David Neale

Reputation: 17058

You'll need to assign the current PageIndex property of the GridView in your sorting method after the sort but before the DataBind.

Upvotes: 1

Related Questions