Click here to Skip to main content
15,794,850 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using grid view , in that i used page indexing and while trying to go to next page by using the page numbers , it is showing an exception as "The GridView 'GridView2' fired event PageIndexChanging which wasn't handled."

What I have tried:

protected void Page_Load(object sender, EventArgs e)
if (!this.IsPostBack)

private void BindGrid()
SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=Test;Persist Security Info=True;User ID=qauser;Password=qauser");
//conn.ConnectionString = "Data Source =;" + "Initial Catalog = test;" + "User Id = qauser;" + "Password = qauser;";
SqlCommand cmd = new SqlCommand("sp_who", conn);
if (conn.State == ConnectionState.Closed)
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
GridView2.DataSource = ds;

protected void OnPaging(object sender, GridViewPageEventArgs e)
GridView2.PageIndex = e.NewPageIndex;
protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e)

GridView2.PageIndex = e.NewPageIndex;
Updated 20-Dec-17 6:38am
ZurdoDev 20-Dec-17 11:20am    
It means your signature of the paging event is not correct.
VamsiMadugula 20-Dec-17 11:23am    
can you please explain me briefly ?
Karthik_Mahalingam 19-Jan-18 8:45am    
Tip: use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
Ram Nunna 4-Jan-18 4:45am    
Have added PageIndex="10" AllowPaging="true" in "GridView2" in HTML page?

1 solution

You haven't wired up the event handler to the event on the grid.

According to the error, your grid has an ID of "GridView2". If you're using AutoEventWireup, then the handler name would need to be GridView2_PageIndexChanging:
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)

If you're not using AutoEventWireup, then you'll need to add the handler in the markup:
<asp:GridView ID="GridView2" runat="server" OnPageIndexChanging="grdView_PageIndexChanging" ...
Share this answer
VamsiMadugula 20-Dec-17 12:18pm    
its not working Richard , instead of returning to next page it is returning to complete empty page which is not at all in that specific gridview
Richard Deeming 20-Dec-17 12:30pm    
You've fixed the exception you were getting; now you need to debug your code to find out what else is going wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900