Some of you might have already realized that DataPager does its job only if you use a DataSource control. For instance, if you want to set a ListView’s DataSource property in page’s Load event and expect DataPager control to successfully page the ListView control, it means that you will need to spend your hours to find why it does not work.
Even though I still can’t figure out why it does not work, here is the workaround. Just create a DataSource control (e.g.: LinqDataSource) control just with “ID” and “runat” properties and then hook the “Selecting” event. Also set the ListView’s “DataSourceID” property to the ID of the DataSource control. What you will do there is to set the “Result” property of the SelectEventArgs argument.
<asp:LinqDataSource ID="LinqDataSource1" runat="server" OnSelecting="LinqDataSource1_Selecting">
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
e.Result = GetDataSource(); // Assuming that GetDataSource method returns the datasource.
Now you can save your hours.