Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a gridview and I want to use paging. I have already set allow paging to true and page size to 5. I can see the numbers at the base of my gridview, but when i click on a number to move to respective page, it throws an error saying:

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
Posted
Updated 27-Sep-12 20:00pm
v2

You can to do following task to achieve this.

1) create a class level static DataTable

C#
static DataTable dtDataForGrid= new DataTable();


2)In the Page_Load method , fill DataTable dtDataForGrid and bind it with GridView.


C#
dtDataForGrid.Rows.Clear();

  //code to fill the DataTable dtDataForGrid

GridView1.DataSource = dtDataForGrid;
GridView1.DataBind();


3) After doing above job. generate the GridView1_PageIndexChanging event. and write the following code.

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

   }



hope this will help you out.

Thanks,
Arshad
 
Share this answer
 
So,

create event of pageindexchange of grid view and assign the new page index to grid view.


C#
protected void GridSummary_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            if (e.NewPageIndex != -1)
            {
                GridSummary.PageIndex = e.NewPageIndex;
                // Call the method to assing datasource to grid view again
            }
            else
            {
                
            }
        }
        catch
        {
        }

    }
 
Share this answer
 
v2
Comments
sakshi1111 28-Sep-12 2:14am    
thanks amolpatil2243......but its not wrnkg...got same error
amolpatil2243 28-Sep-12 2:18am    
please share your code.
amolpatil2243 28-Sep-12 2:24am    
after setting new page index you need to call the data bind method to grid view again...

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