GridView Error with Solution: The GridView 'GridView' fired event PageIndexChanging which wasn't handled.

This post is a quick tip for beginners who have started working with Asp.Net GridView control using C# (CSharp) language. Let me assume, you have a GridView control on your web page. You run the application and you click a pager link button to navigate to the next GridView page. Suddenly, you see an error message on your browser, which says, “The GridView ‘GridView’ fired event PageIndexChanging which wasn’t handled.

The GridView ‘GridView’ fired event PageIndexChanging which wasn’t handled

Why it happened?

It’s not unusual. It happened because, while adding the GridView control on your webpage, you have set the AllowPaging property as true and have assigned a PageSize. For example,

AllowPaging PageSize="5"

And in a rush, you have written the code behind procedure to connect the GridView with a database object (table etc.) and have run the application. Everything works fine until you click the navigation or pager link button to view the next GridView page.


The error occurred since you are not handling the PageIndexChanging event. That is you have to set the PageIndexChanging event in your design mode.

The correct procedure is to add the PageIndexChanging event immediately after adding attributes like AllowPaging and PageSize. Here is it …

AllowPaging PageSize="5"

Next, add the event handler in your code behind procedure.

protected void GridView_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
    GridView.PageIndex = e.NewPageIndex;            // GRIDVIEW PAGING.

This is the correct procedure.
Here you can learn more about this event: GridView.PageIndexChanging Event

Hope this fixes the error.

Previous - How to Bind Data to GridView Control using DataSet in Asp.Net C# and Vb.Net – Quick TipNext - Change the Background Color or the Text Color of a GridView Cell Based on Condition in Asp.Net C#

Like this Article? Subscribe now, and get all the latest articles and tips, right in your inbox.

Enter your email id

Delivered by FeedBurner

Related Posts: