c# - 如何将 gridview 数据绑定(bind)到 ExpandoObject

标签 c# dynamic expandoobject expando

当我尝试对 ASP.NET 进行数据绑定(bind)时 GridViewIEnumerable<ExpandoObject>使用 ObjectDataSource , 我得到以下异常。

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

任何人都知道我如何将数据绑定(bind)到 ExpandoObjects

最佳答案

开源框架 Impromptu-Interface可以做到这一点。它有一种通过传入属性名称->类型的字典来公开动态对象属性以进行反射的方法。

IEnumerable<dynamic> tProxiedObject = listOfExpandos.Select(x=>Impromptu.ActLikeProperties(x, x.ToDictionary(k=>k.Key,v=>typeof(object))));

关于c# - 如何将 gridview 数据绑定(bind)到 ExpandoObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4740969/

相关文章:

c# - Linq 查询 Group By 和 contains

c# - 方法 'Open' 没有重载需要 1 个或多个参数

c# - 如何将 BitmapImage 转换为 Icon?

dynamic - Jade : how does one assign the 'checked' attribute to dynamically generated radio button inputs?

c# - TPL 任务 + 动态 == OutOfMemoryException?

c# - 动态地向动态对象添加属性?

c# - 用户控件事件

python - 类语法和 type() 有什么区别?

javascript - angularjs的动态函数调用

c# - 为什么我不能这样做 : dynamic x = new ExpandoObject { Foo = 12, Bar = "twelve"}