The GridView fired event PageIndexChanging which wasn’t handled

If you’ve set a gridviews AllowPaging attribute to “true”, you’ll notice the following error;

The GridView fired event PageIndexChanging which wasn’t handled

To setup paging with Gridviews, you also need to set the page index property to the new page that you wish to view. Funny enough, this is extremely easy to do. See below for a code example written in C#.

The ASPX page

<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="true" AllowPaging="true" PageSize="10" OnPageIndexChanging="gvList_PageIndexChanging">

and the C# code

    protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        bindGrid();

        gvList.PageIndex = e.NewPageIndex;
        gvList.DataBind();
    }
Did you like this? Share it:

No related posts.



31 Responses to “The GridView fired event PageIndexChanging which wasn’t handled”

  1. Khizer says:

    Hey dude..Thanks …helped a lot…

  2. fayjaa says:

    thank you so much

  3. exactly what I’am looking for, great!

  4. Tom says:

    In my case, after adding those codes, the same exception will not be triggered, but all the other pages will not be displayed except the very first page. It is a total blank after I clicking page 2 or 3, or 4, 5 ….

  5. Ivan says:

    Thanks a lot. It worked for me!

  6. Daren says:

    Thanks for the help, much appreciated!

  7. JAM says:

    This is the problem and this is the exact solution for this type of exception

  8. AP says:

    I have tried the code supplied, but my code does not recognise bindGrid() as being in the current context.

    What am I missing?

  9. sepide says:

    tnx very very very much,ure site is the best,tnx

  10. k.inthu says:

    Thank Q u

  11. nandagopal says:

    very nice its very useful

  12. Rex Trayn says:

    Aparently that fix does not work for everyone.

    I have been trying to make grid view paging work on 2 different computers. One with Vista and VWD 2008 and one with XP and visual studio 2008.

    I get the unhandled event error when clicking on the page number if I dont put code in the handler. If I put the code in the handler, my gridview disapears from the web page.

  13. Shebin says:

    Great..Helped a lot..
    Thanks

  14. Deep says:

    Thanks a lot buddy, but the ultimate credit goes to supradipda for helping me to learn the fundamentals and how to search problems on net

  15. Santhosh says:

    Thanks a lot, your steps helped me in making grid work.

  16. Eric says:

    Thanks for the post, this was my first grid. After trying several examples this worked great!!!!

    Thanks alot…

  17. Mohsen says:

    Thanks alot…

  18. Narender says:

    Awesome dude. You saved me a day.. Rocks !

  19. PraveenT says:

    Thank u very much!

  20. sagar says:

    thanks a lot……….

  21. Bincy says:

    Great work …Thanks a lot…

  22. SAN says:

    Great Work It helped me lot

  23. Vikram says:

    Thanks a lot it worked.

  24. sajid says:

    the error is gone but on page second nothing is displaying.

  25. Joel Hallan says:

    I have tried the code supplied, but my code does not recognise bindGrid() as being in the current context.

  26. Rishan Singh says:

    Thanks alot, works well

  27. Tre Hart says:

    Thanks a lot for short explanation, but really help me…

  28. codertuhin says:

    Thanks…it works now!

  29. behbod says:

    thanks :)

  30. The article is worth reading,Thank you very much! I will keep your new articles.

  31. Srinivas says:

    In my case, after adding those codes, the same exception will not be triggered, but all the other pages will not be displayed except the very first page. It is a total blank after I clicking page 2 or 3.
    now what am doing,please help me

Leave a Reply

You must be logged in to post a comment.