zohair
zohair

Reputation: 2369

gridview_paging messing up

I have an asp.net C# web app. In it I have a gridview. The gridview gets search results from a database. Sometimes there are a lot of results, and so I wanted to use paging. Here's what I tried:

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

For some reason, when I click on a page number, it shows me the EmptyDataText(There are no records to display). What code would work? Please help.

Thank you

Upvotes: 3

Views: 248

Answers (3)

gwt
gwt

Reputation: 2413

Try this code It will absoloutly work :

protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

    GV.PageIndex = e.NewPageIndex;
    BindGrid();
}

    public override void BindGrid()
{
    query = new CommonQueries();
    GV.DataSource = query.getAllBooks();
    GV.DataBind();
}

the problem with your code is that you did'nt reassign the data source to your gridview !

Upvotes: 0

Zinx
Zinx

Reputation: 2349

Try assigning the datasource in NeedDataSource event.

Cheers.

Upvotes: 1

Chris
Chris

Reputation: 2991

You need to reassign your datasource to grdResults before the call to DataBind().

Upvotes: 0

Related Questions