The GridView 'GridView1' fired event PageIndexChanging which wasn't handled
This error is caused when an aspx page contains a GridView which has pagination enabled, but the PageIndexChanging event has not been handled.
This had me stumped for a short while today whilst coding a C# ASP.NET web application. If you have pagination turned on, you'll need to create a handler for your GridView, thus:
Note that in the above example I also explicitly set the new PageIndex, and rebind the DataSource. The reason being that if you don't, changing pages doesn't work.
This had me stumped for a short while today whilst coding a C# ASP.NET web application. If you have pagination turned on, you'll need to create a handler for your GridView, thus:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// Increment Page Index
GridView1.PageIndex = e.NewPageIndex;
// Need to rebind or page does not change
GridView1.DataSource = MyDataSet;
GridView1.DataBind();
}
Note that in the above example I also explicitly set the new PageIndex, and rebind the DataSource. The reason being that if you don't, changing pages doesn't work.
Labels: Code Snippets, Web Development
0 Comments:
Post a Comment
<< Home