【问题标题】:How to databind a gridview to an ExpandoObject如何将网格视图数据绑定到 ExpandoObject
【发布时间】:2011-01-19 21:27:34
【问题描述】:

当我尝试使用 ObjectDataSource 将 ASP.NET GridView 数据绑定到 IEnumerable<ExpandoObject> 时,出现以下异常。

System.Web.HttpException (0x80004005):DataBinding:“System.Dynamic.ExpandoObject”不包含名为“StoreID”的属性。

有谁知道我如何将数据绑定到ExpandoObjects

【问题讨论】:

  • 我知道这是可以做到的 - I've done it - 不幸的是,我在那个练习中丢失了一些文件。如果它很重要,我可能会重建它,但这里的关键将类似于 ICustomTypeDescriptor 和/或 ITypedList

标签: c# dynamic expandoobject expando


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多