Home Contact RSS

Using DataPager with Code-Behind Data Source

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">
</asp:LinqDataSource>  

 

protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = GetDataSource(); // Assuming that GetDataSource method returns the datasource.
}  

Now you can save your hours.

Arnaud said,

June 30, 2008 @ 10:33

Thanks for the info, that was useful!

asp.net said,

August 22, 2008 @ 20:48

thx, it was very very useful.

Boguslaw Faja said,

September 11, 2008 @ 20:03

Thanks a lot! You just found a place inside my rss reader ;-)

Ahmad said,

November 4, 2008 @ 15:19

Thank you sooooooooooooooooooooooo much. I save 1000 hours.

Josh said,

November 12, 2008 @ 16:59

Thanks, this worked great!

RSS feed for comments on this post · TrackBack URI

Leave a Comment