will the grid control bind to an IQueryable and function

Jan 18, 2010 at 5:44 PM

All --

Please help.

I need to know if the grid control will bind to an IQueryable and function, with auto-sort, etc.

Can that be done?

If yes, then is there a code sample?

(I am using L2s for all my data access so I get back an IQueryable in the typical calls to me BusinessLayer.)

Thank you.

-- Mark Kamoski

Coordinator
Jan 19, 2010 at 12:54 AM
Edited Jan 19, 2010 at 12:56 AM

CoolGridView is ASP.NET GridView under the hood. So, you might want to try LinqDataSource control. Look at this good article by Scott Guthrie http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

Coordinator
Jan 19, 2010 at 2:42 AM
Edited Jan 20, 2010 at 9:44 PM

Try this out:

  1. Drop a CoolGridView and a LinqDataSource control into your ASPX page.
  2. In the "Properties" toolbox, set the DataSourceID of CoolGridView to point to your LinqDataSource control.
  3. Set the properties of CoolGridView control to the following:
    1. AllowPaging : True
    2. AllowSorting : True
  4. Handle the "Selecting" event of LinqDataSource
  5. In the "Selecting" event handler, call your method that returns an IQueryable<> object and assign it to the event arguments "e.Result".

Now, you should be able to bind the result of your method to CoolGridView with automatic sorting and paging. Tell me if this helped. I will be posting more about this on my blog.

Coordinator
Jan 19, 2010 at 2:47 AM
Edited Jan 20, 2010 at 9:45 PM

Try this out:

  1. Drop a CoolGridView and a LinqDataSource control into your ASPX page.
  2. In the "Properties" toolbox, set the DataSourceID of CoolGridView to point to your LinqDataSource control.
  3. Set the properties of CoolGridView control to the following:
    1. AllowPaging : True
    2. AllowSorting : True
  4. Handle the "Selecting" event of LinqDataSource
  5. In the "Selecting" event handler, call your method that returns an IQueryable<> object and assign it to the event arguments "e.Result".

Now, you should be able to bind the result of your method to CoolGridView with automatic sorting and paging. Tell me if this helped. I will be posting more about this on my blog.

Jan 19, 2010 at 5:02 PM

jesobrepena wrote:

...Drop a CoolGridView and a LinqDataSource control into your ASPX page.....

Jes --

Please help.

If one uses a LinqDataSource, and L2s, then one (more or less) gets automatic paging and sorting, as noted here...

http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

...so what then would be the advantage of using a CoolGridView?

Please advise.

Thank you.

-- Mark Kamoski

Coordinator
Jan 19, 2010 at 10:04 PM

Hi Mark,

CoolGridView is server-side control that extends ASP.NET GridView to provide 1) fixed headers, 2) fixed footer, 3) fixed pager and 4) scrollable content. Development is ongoing to pack CoolGridView with more features such as Hierarchical data presentation, Resizable column widths and more. Please refer my blogs for more details:

  1. Extend ASP.NET GridView to Support Fixed Header, Fixed Footer and Scrollable Content
  2. Render ASP.NET GridView Control with Resizable Column Header
  3. How this Idea Sparked

If you have more questions, please let me know.

Jan 20, 2010 at 3:30 PM
jesobrepena wrote:

...

4. Handle the "Selecting" event of CoolGridView

...

Jes --

That line should read something like...

4. Handle the "Selecting" event of the LinqDataSource.

...but, aside from that minor typo, your solution works great.

Wow, you did a REALLY nice job on this code.

It is going into production here today.

Thank you SO much.

That said, I am a bit wary to ask for more, and appear greedy-- so, let's just say if one wanted to improve this already excellent code then one might consider the following minor tweaks.

Wish List Item #1: Make it so the grid can size relatively (width="95%") and have the vertical scrollbar automatically attach to the right-hand-side of the GridView.

Wish List Item #2: Make it so the columns will size relatively to use the available space, (as opposed to the current functionality where one has to set the column widths statically).

Regardless, the code is great as-is.

Thank you.

-- Mark Kamoski

Coordinator
Jan 20, 2010 at 9:49 PM

Hi Mike,

Thank you for the correction. I have updated my previous posts to reflect that.

Great to know that the control worked well for you. I'll make sure to consider your wishlist suggestions on future releases.

And thank you for taking the time to rate the latest release. It's very encouraging :-)

- John