Published by John Eric Sobrepena on Jan 21, 2010
I recently received a question about how to data bind CoolGridView to an object of type IQueryable<> with automatic sorting and paging. CoolGridView extends ASP.NET GridView control. GridView does not directly support DataSource of type IQueryable<>, and the same is true for CoolGridView. We can use LinqDataSource control to bridge the gap. Quickly bind CoolGridView control to IQueryable<> with automatic sorting and paging capability by following these easy steps.
- Drop a CoolGridView and a LinqDataSource control into your ASPX page.
- In the "Properties" toolbox, set the DataSourceID of CoolGridView to point to your LinqDataSource control. Set the properties of CoolGridView control to the following:
- AllowPaging : True
- AllowSorting : True
- Handle the "Selecting" event of LinqDataSource
- In the "Selecting" event handler, call your method that returns an IQueryable<> object and assign it to the event argument's property "e.Result".
There you have it!
Have a great weekend everyone.
Labels: ASP.NET, CoolGridView, Data Binding, GridView, IQueryable, LinqDataSource
Subscribe to feed