Linq Results for Paging in a Datagrid

Today I was using c#'s new Linq technology to query a list of objects.  To keep my test simple, I decided to try ordering my objects.

My code look looked like this:

var query = from o in referrals orderby o.Email select o;

I bound this to a gridview.  Everything looked ok until runtime.  My datagrid complained:

The data source does not support server-side data paging.

 A quick google search revealed a post by Scott Guthrie.  I need to tell Linq that I wanted this list back in a form that the datagrid could page.  Modified:

var query = (from o in referrals orderby o.Email select o).ToList() ;

This worked well, and gave me my referral list back, ordered by the Referral object's Email attribute.  Of course, this only scratches the surface of what Linq can do, as filtering or joining of that list would be better examples of the power of Linq.

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this entry.
Comments

  • 10/2/2009 10:34 AM Phil wrote:
    This is the way a blog should be- cut to the chase and saved the verboseness for psychologists and mamas. It helped me solve a problem. Good job!
    Reply to this
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.