views:

946

answers:

4

Hello,


According to my book all that is needed to start using automatic paging is to set GridView.AllowPaging to true. But when I try to navigate to another page, I get GridView fired event PageIndexChanging which wasn't handled exception. I then have to create event handler for PageIndexChanging event, but then when I navigate to next page, GridView doesn’t display anything.

Q1 - What am I doing wrong?

Q2 - Book is written for Asp.Net 3.5, but none of the behavior described above is mentioned by the author?! Any thoughts why my GridView behaves so differently?


thanx

EDIT:

I'm embarassed to say, but reason it didn't work is because I forgot to remove the line

if(IsPostBack) GridView.DataSourceID="";


Sorry for taking your time and thanx for helping me

+3  A: 

It's been a while, but don't you have to set the page and rebind your data? From memory, something like ...

gv.PageIndex = e.NewPageIndex
// Rebind Grid
JP Alioto
+2  A: 

When you post back, you'll have to rebind the data to the gridview.

You may also need to set the page number like:

GridView1.CurrentPageIndex = e.NewPageIndex;
MikeW
+1  A: 

If you use the ObjectDataSource as your GridView's data source, you don't have to do those code-behind methods - it's all handled for free.

Rafe Lavelle
+1  A: 

Check this article

YordanGeorgiev
This link is dead.
saturdayplace
http://www.codeproject.com/KB/webforms/GenericGvWithSortAndPage.aspx
Aristos