Take the following example...a page with a ListView
and a DataPager
used for paging the data of the ListView
:
Code Behind:
The problem is due to the binding occuring on the Page_Load
event.
For this to work as expected, the binding needs to happen in the DataPager
's OnPreRender
event, not in the Page_Load
.
Source:
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
//Binding code moved from Page_Load
//to the ListView's PreRender event
}
protected void ListPager_PreRender(object sender, EventArgs e)
{
MyList.DataSource = GetSomeList();
MyList.DataBind();
}