Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
3.00/5 (4 votes)
See more:
When I click the page number then error is

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
How to handle it?
When I try
this
C#
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource = GetData();
            GridView1.DataBind();
        }


during the build error is
'System.EventArgs' does not contain a definition for 'NewPageIndex' and no extension method 'NewPageIndex' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)
Posted
Updated 24-Jan-20 5:59am
v2

try this,

in gridview's pageindexChanging property,

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;

    //rebind your gridview - GetSource(),Datasource of your GirdView
    GridView1.DataSource = GetSource();
    GridView1.DataBind();

}


hope it helps, mark this as answer if it helps you

thanks
 
Share this answer
 
Comments
Prince Antony G 28-Nov-11 3:40am    
Try this
sathish kumar 25-Sep-13 4:31am    
The name 'GetSource' does not exist in the current context
Member 7909353 15-Jan-20 23:51pm    
When I have all data to bind then what need to be rebind and get from database
Try this:

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataSource = //get datasource (list or datatable)
    GridView1.DataBind(); //bind data
}


-Eduard
 
Share this answer
 
Comments
[no name] 16-May-19 9:21am    
Thanks, that method worked for me
You need to handle the PageIndexChanging event for the grid like

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    //Bind grid

}
 
Share this answer
 
v2
first check
AllowPaging="True" 

or not. if not "True".then make it "true>"

then in ur PageIndexChanging event write this code
C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    bindData();
}
 
Share this answer
 
To use paging in GridView you need to take care of following things
1. Give PageSize
2. write PageIndexChanging event
You have not define GridView1_PageIndexChanging in your codebehind
check following code

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    //Bind grid
}
 
Share this answer
 
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// Set the new page index
GridView1.PageIndex = e.NewPageIndex;

// Rebind the GridView with the updated page index
BindGridView(); // Implement this method to bind data to the GridView

// Optionally, cancel the default behavior by setting e.Cancel to true
e.Cancel = true;
}
 
Share this answer
 

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