-2

I'm getting "The GridView 'grdFiles' fired event PageIndexChanging which wasn't handled." even if I've added the event handler:

protected void grdFiles_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GetFiles();
        grdFiles.PageIndex = e.NewPageIndex;
        grdFiles.DataBind();

    }

Any ideas?

Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62

1 Answers1

0

Try this code. You need to declare a method on your code behind that handles the PageIndexChanging event.

protected void grdFiles_PageIndexChanging (object sender, GridViewPageEventArgs  e)
{
grdFiles.PageIndex = e.NewPageIndex;
bindGridView()
}

the method bindGridView() is

private void bindGridView()
{
 grdFiles.DataSource=.....;
 grdFiles.DataBind();
}
Linga
  • 10,379
  • 10
  • 52
  • 104
  • Where is the diference with that and the code I wrote? Also, I have tried to redefine datasource and reBind the grid within the event handler. Didn't work. – Ladislav Biskupec Mar 30 '13 at 09:54
  • I already have method GetFiles() that binds data just fine on the first page. The problem occures when I change the page on the gridView. Then I get the message that event wasnt handled (even that it should be). Is there something I'm missing in Your answer? – Ladislav Biskupec Mar 30 '13 at 10:04
  • If you have set a gridviews AllowPaging attribute to “true” – Linga Mar 30 '13 at 10:22
  • Alos, If you set AllowPaging="true" or AllowSorting="true" on a GridView control without using a DataSourceControl DataSource (i.e. SqlDataSource, ObjectDataSource), you will run into this kind of error – Linga Mar 30 '13 at 10:24
  • Thank You for Your effort. That link didn't solve my problem on the spot but guided me to a solution. Problem solved and I'll give You "Thumbs up"! – Ladislav Biskupec Mar 30 '13 at 11:01