GridView bound with Properties of nested class

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:

<asp:TemplateField>
    <itemtemplate>
        <p><%#DataBinder.Eval(Container.DataItem, "NestedClass.Name")%></p>
    </itemtemplate>
</asp:TemplateField>

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

Leave a Comment