3

Has anyone found a way to dynamically create a grid using ExpandoObject, DynamicObject or Reflection.Emit and at the same time allow CRUD operations?

I was able to use Reflection.Emit to dynamically create my grid columns and display data, but once I try to edit a row, the cell contents disappear.

Any help would be greatly appreciated!

JoBot
  • 131
  • 1
  • 7

2 Answers2

1

There is a project showing how to use dynamic objects with Telerik Grid for ASP.NET MVC. You can find it here: http://www.telerik.com/community/code-library/aspnet-mvc/grid/binding-to-a-collection-of-dynamic-objects-with-mvc3-razor.aspx

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
  • Have you tried this with `ExpandoObject` or the like? I am experiencing the same problem as @JoBot right now: After binding the grid to `dynamic` (`ExpandoObject`) via AJAX, the rows are there, but all cells are empty, even though the returned JSON data looks alright. Could the problem be that those objects are serialized as in a Key-Value structure instead of a "real" JSON object? – hangy May 07 '12 at 11:50
1

I was able to solve the problem by using this code. The normal JavaScriptSerializer that's used by ASP.NET MVC to produce the JSON output serializes ExpandoObject similarly IDictionary<string, object>, so that instead of the required JSON object, the data array actually contains a list of key-value pairs, which the Telerik ASP.NET MVC grid cannot work with.

Community
  • 1
  • 1
hangy
  • 10,765
  • 6
  • 43
  • 63
  • Sorry for being MIA since my first post, but I got pulled into a completely different project. In any case... @hangy thank you for the suggestion. You are right on spot with the key-value pairs that Telerik's MVC grid cannot handle when using ExpandoObject. As for my original post regarding the missing cell values when modifying rows, it turned out that I made a silly mistake of not adding the template that the grid will be using in \EditorTemplates. – JoBot Jun 20 '12 at 17:29