0

I am writing my own event handler for GridView in PageIndexChanging event, I didn't explicit set the DataSourceID for my GridView, here is my code:

Code for GridView data binding:

protected void DetailsView_DataBound (object sender, EventArgs e ) 
{
    Customer cust = (Customer)DetailsView.DataItem;
    this.GridView.DataSource = cust.Orders;
    this.GridView.DataBind();
}

This part of the code allows me to show order details in GridView when data bound with DetailsView. Then I write my own GridView_PageIndexChanging event handler and DOES NOT work for me:

protected void GridView_PageIndexChanging(object sender, EventArgs e)
{
    GridView.PageIndex = e.NewPageIndex();
    GridView.DataBind();
}

If I click the next page number, the website shows nothing. But if I change GridView.DataBind() to DataBind() The paging works.

Anyone has any idea why the second Databind method works and what is the reason?

Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62
user1969492
  • 1
  • 1
  • 1

2 Answers2

0

the second databind is DataBind(Page.DataBind) which refrence to current page binds all page controls and its child controls.

Sumit
  • 196
  • 1
  • 8
  • This is the part confuse me. I am binding data with my GridView, why should I call Page.DataBind() method instead to make to databind work. – user1969492 Jan 13 '13 at 22:44
0

Have you set allowPaging="True" of gridview. if not then set it to true.

Ankush Jain
  • 5,654
  • 4
  • 32
  • 57
  • Yes, I did.I set AllowPaging="ture" and onpageindexchanging="GridView_PageIndexChanging". In my situation, I only need to change GridView.DataBind() method to DataBind() method to make my paging codes work. – user1969492 Jan 13 '13 at 21:56