3

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

0

3 Answers 3

1

Try assigning the datasource in NeedDataSource event.

Cheers.

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

Only if it isn't already declared in markup or in, say, a Load event. Do you have ViewState disabled? If not, I don't think you'd need to re-databind unless your data source only contains the displayed records (and omits the ones on other pages).
You're right. I don't need to rebind the data. But now, it doesnt change the the page until I click the page number twice...
0

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 !

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.