Gridview_paging will go bad

I have an asp.net c # web application. In it I have a gridview. Gridview retrieves search results from a database. Sometimes there are many results, so I wanted to use paging. Here is what I tried:

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

For some reason, when I click on the page number, it shows me an EmptyDataText (there are no entries to display). What code will work? Please help.

thanks

+3
source share
3 answers

Try to assign a data source in the NeedDataSource event.

Greetings.

+1
source

You need to reassign your data source to grdResults before calling DataBind ().

0
source

. :

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();
}

, gridview!

0
source

Source: https://habr.com/ru/post/1718406/


All Articles