Thursday, 22 March 2012

ASP DataPager double click to move page

I have only just got around to using the .NET 4.0 DataPager control, and whilst impressed at the simplicity of setting it up, I was annoyed with two features:

1) You have to bind it to a ListView, it does not work with a Repeater control which is a little strange as exactly what I was achieving in the repeater I can do with no code change to get it to work in the ListView
2) When you want to page, say from page 1 to page 2 of the results, you have to double click the "next" button twice to move forward.

Nothing I can do about 1) above, but as for 2), just ensure that the listview it is being re-bound during the pagination by adding the OnPagePropertiesChanged attribute to the ListViews markup, e.g:

OnPagePropertiesChanged="lstSearchResult_OnPagePropertiesChanged"

and in the code behind, bind on the event

protected void lstSearchResult_OnPagePropertiesChanged(object sender, EventArgs e)
{
     lstSearchResult.DataBind();
}

2 comments: