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.

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