My first MSDN Magazine article is up: Get the Most out of WebGrid in ASP.NET MVC. So, if you want to find out how to make the WebGrid component from WebMatrix fit in with ASP.NET MVC then take a peek…. http://msdn.microsoft.com/en-us/magazine/hh288075.aspx.
Thanks to Carl Nolan and Simon Ince for reviewing the article :-)
**UPDATE - the helpers are now up on NuGet: http://blogs.msdn.com/b/stuartleeks/archive/2012/01/24/webgrid-extensions-on-nuget.aspx **
I read your article, it was well written and very informative.
Good job! Congratulations on your first publication. Many more to follow I hope.
Good article, but what is the SafeCast method that you are using? I am guessing some extension method, but I haven't found any such method in the framework, and a Google search provides numerous hits, none of which appear to be an exact match.
the SafeCast was a little extension method that slightly simplified the code listing by removing a null check. It's in the code download under Infrastructure\EnumerableExt
public static class EnumerableExtensions
public static IEnumerable<TTarget> SafeCast<TTarget>(this IEnumerable source)
return source == null ? null : source.Cast<TTarget>();
Thanks Stuart. Somehow I managed to completely miss the fact that there was a download.
Can you please explain how to edit WebGrid Column values.
i.e i want user insert some values in our Gridview and on basis of values i have to display some calculation in gridview.
Great article Stuart. Is there a way to use WebGrid (or any other equivalent control is ASP.Net MVC) to select multiple rows ?
@Siva, you could render the grid inside a <form> and render a custom column in the grid that is a checkbox. Submitting the form would then include any checkboxes that were selected. This wouldn't work across pages in the grid, but aside from that should be a relatively simple solution
Stuart - this looks awesome! Question : do you know if it is compatible with MVC 4?
Kevin, I've not fully tested it by any means, but it worked in the ASP.NET MVC 4 project that I included it in a few days ago
Hey Stuart, Nice Article. I was wodering if i could limit the user to check upto 3 checkboxes across different pages. I somehow got it working but it works for each page and not across. (when i move to 2nd page all the 1st page selections are erased). Please briefly let me know how could i deal with this.
Another quick question of mine is could we reverse sort?( in the code and not on the address bar) I am doing a default sort on totalVotes column and it shows up in ascending order but i wanted the descending order, can i choose the order??
It is a nice article. Can a scroll bar be added to the grid?
@Girish. Have you tried setting the height of the grid element (or one of its container elements)?