9

When I try to databind an ASP.NET GridView to an IEnumerable<ExpandoObject> using an ObjectDataSource, I get the following exception.

System.Web.HttpException (0x80004005): DataBinding: 'System.Dynamic.ExpandoObject' does not contain a property with the name 'StoreID'.

Anyone know how I could databind to ExpandoObjects?

dbc
  • 80,875
  • 15
  • 141
  • 235
EtienneT
  • 4,561
  • 5
  • 32
  • 35
  • I know it can be done - [I've done it](http://marcgravell.blogspot.com/2008/11/dynamic-objects-part1.html) - unfortunately I lost some files from that exercise, though. If it is important I could probably reconstruct it, but the key here will be something like `ICustomTypeDescriptor` and/or `ITypedList` – Marc Gravell Jan 19 '11 at 22:07

1 Answers1

6

The opensource framework Impromptu-Interface can do this. It has a method for exposing dynamic object properties for reflection by passing in a dictionary of property names->types.

IEnumerable<dynamic> tProxiedObject = listOfExpandos.Select(x=>Impromptu.ActLikeProperties(x, x.ToDictionary(k=>k.Key,v=>typeof(object))));
jbtule
  • 29,889
  • 11
  • 91
  • 126
  • This works. But it does not support two way binding. When i try to update, the object sent to the update method is empty. – OrPaz Mar 10 '13 at 18:55
  • 2
    @OrPaz: you could try ImpromptuInterface.MVVM https://www.nuget.org/packages/ImpromptuInterface.MVVM/4.0.13 – RBZ Jul 07 '14 at 15:58