Reputation: 10815
I have a grid view which has 10 rows. I have set paging = true
and pageSize = 2
Now when I try to navigate through the page by the below mentioned link like 1, 2, 3
, I then receive error something like need event pageIndexChanged
.
I added this event but do not understand what code should I add to this event to navigate to next page by maintain the state in each page ?
Please let me know
Upvotes: 3
Views: 3369
Reputation: 73123
All you need to do is set the PageIndex for the GridView to the new page, and re-bind the control.
protected void gridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridView1.PageIndex = e.NewPageIndex;
BindGrid(); // this is whatever method you call to bind your data.
}
EDIT:
You should already have an event-handler for the DataBound event of the GridView:
protected void GridView1_DataBound(object sender, EventArgs e)
{
// lots of code here to do stuff with bound data.
}
Instead of having "lots of code", you have this:
protected void GridView1_DataBound(object sender, EventArgs e)
{
BindGrid();
}
Therefore on the PageIndexChanging event, all you're doing is re-binding the data (calling the same logic for the DataBound event).
Make sense?
Upvotes: 1