views:

86

answers:

1

I have a List (Of MyObject) binding to a GridView in the Page_Load event. MyObject has a child object as a property, ChildObject which also has a property itself, ChildProperty.

In my GridView, I would like to bind one of the fields to ChildProperty, but doing something like:

<asp:boundfield datafield="ChildObject.ChildProperty" />

results in an error:

System.Web.HttpException: A field or property with the name 'ChildObject.ChildProperty' was not found on the selected data source.

How do I bind to that property, or is it not possible? I suppose I could create a ReadOnly property in my parent object just to read the child property, but that's a bit smelly.

Any ideas?

Thanks!

+3  A: 

You can use:

<asp:TemplateField>
    <ItemTemplate>
    <%# DataBinder.Eval(Container, "DataItem.Property.ChildProperty.GrandChildProperty") %>
    </ItemTemplate>
</asp:TemplateField>
Rex M
ah, true. was hoping for an easier way, but this definitely works
Jason