GridView bound with Properties of nested class

后端 未结 2 1905
情书的邮戳
情书的邮戳 2020-11-29 10:48

I have an object map similar to what\'s listed below. When I try to bind the properties of NestedClass in a GridView I get the error:

\"A field or pro

2条回答
  •  清歌不尽
    2020-11-29 11:19

    Only immediate properties of an instance can be displayed in a BoundField column.

    One must instead use DataBinder.Eval in an itemtemplate to access the nested property instead of assigning it to a boundfield.

    Example:

    
        
            

    <%#DataBinder.Eval(Container.DataItem, "NestedClass.Name")%>

    Alternatively, you can create a custom class which inherits BoundField and overrides GetValue to use DataBinder.Eval, as described in this blog post:

    http://web.archive.org/web/20120121123301/http://iridescence.no/post/FixingBoundFieldSupportforCompositeObjects.aspx

提交回复
热议问题