简体   繁体   中英

How to databind a gridview to an ExpandoObject

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 ?

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))));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM