How to databind a gridview to an ExpandoObject

房东的猫 提交于 2019-12-01 00:59:27

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/4740969/how-to-databind-a-gridview-to-an-expandoobject

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!