Click here to Skip to main content
14,360,787 members
Rate this:
Please Sign up or sign in to vote.
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
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 22-Oct-19 19:35pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

try this,

in gridview's pageindexChanging property,

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
   
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
Rate this:
Please Sign up or sign in to vote.

Solution 4

Try this:

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


-Eduard
   
Comments
[no name] 16-May-19 9:21am
   
Thanks, that method worked for me
Rate this:
Please Sign up or sign in to vote.

Solution 1

You need to handle the PageIndexChanging event for the grid like

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

}
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 5

first check
AllowPaging="True" 

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

then in ur PageIndexChanging event write this code
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    bindData();
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    //Bind grid
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 6

You are using "OnPageIndexChanged" event..

Instead use "OnPageIndexChanging" event
   
Comments
CHill60 19-Jun-15 8:36am
   
You have brought nothing new to this post which is over 3 years old. OnPageIndexChanging mentioned in all previous 5 solutions
Member 12804771 25-Oct-16 7:02am
   
i have a problem regarding gridview page index changing
i am code for this
grdview.PageIndex = e.NewPageIndex;
grdview.DataBind();
at the time of compilation i have got a error-
Error 1 'System.Web.UI.WebControls.GridViewSelectEventArgs' does not contain a definition for 'NewPageIndex' C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\WebSite8\SqlDatamaniputeOperations On Database.aspx.cs C:\...\WebSite8\ 35 207
please tell me how to resolve this

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100