How to databind a gridview to an ExpandoObject

8

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?

c#
dynamic
expandoobject
expando
asked on Stack Overflow Jan 19, 2011 by EtienneT • edited Mar 3, 2020 by dbc

1 Answer

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))));
answered on Stack Overflow Feb 28, 2011 by jbtule

User contributions licensed under CC BY-SA 3.0