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?