Snap to property

I have a binding List (Of MyObject)

to a GridView on an event Page_Load

. MyObject

It has a child object as a property, ChildObject

which also has a property 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 named "ChildObject.ChildProperty" was not found in the selected data source.

How do I bind this property, or is it not possible? I suppose I could create a ReadOnly property on the parent's read-only child property, but that is a little smelly.

Any ideas?

Thank!

+2


source to share


1 answer


You can use:



<asp:TemplateField>
    <ItemTemplate>
    <%# DataBinder.Eval(Container, "DataItem.Property.ChildProperty.GrandChildProperty") %>
    </ItemTemplate>
</asp:TemplateField>

      

+4


source







All Articles