mohammad reza
mohammad reza

Reputation: 3442

Error in Gridview application

When trying to use the paging part of GridView in my application, I receive the following error:

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.

Upvotes: 1

Views: 454

Answers (4)

Joe Swan
Joe Swan

Reputation: 200

You need to add an eventhandler to tell the GridView which page it should be looking at as I'm guessing you have done the .DataBind() in code. An example would be:

Markup:

<asp:GridView ID="GridView1" runat="server"
    EnablePagingAndSortingCallbacks="true"
    OnPageIndexChanged="GridView1_PageIndexChanged" />

Code:

    protected void GridView1_PageIndexChanged(object sender,
                                              GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }

Upvotes: 3

Yordan Georgiev
Yordan Georgiev

Reputation: 5420

For this type of problems one could use custom controls

Upvotes: 0

mohammad reza
mohammad reza

Reputation: 3442

I mixed your answers and I get my answer. I solved this problem whit this code :

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

Upvotes: 1

eKek0
eKek0

Reputation: 23289

It means that the dataset associated with the gridview doesn't support paging.

It doesn't mean that you can't paged with it. To do that you will need to write your own code in PageIndexChanging event.

Upvotes: 0

Related Questions