Reputation: 2369
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
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
Reputation: 2991
You need to reassign your datasource to grdResults before the call to DataBind().
Upvotes: 0