Home > ASP.NET, c# > Binding to an ObjectDataSource where the Object has Child Objects

Binding to an ObjectDataSource where the Object has Child Objects

I was trying to bind a DetailsView to an ObjectDataSource and display child class properties of the main Object I was binding to. I had a BillingObject with a child object called AddressObject.

My failed attempt:
<asp:BoundField DataField=”BillingAddress.State” HeaderText=”State” SortExpression=”BillingAddress.State” />

I did a little research and found out the idea is very possible. In case anyone else comes across this, you have to use an ItemTemplate:
<asp:TemplateField HeaderText=”First Name” SortExpression=”Person.FirstName”>
    <ItemTemplate>
        <asp:Label ID=”FirstNameLabel” runat=”server” Text=’<%# Eval(“Person.FirstName”) %>’></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

Categories: ASP.NET, c# Tags:
  1. No comments yet.
  1. No trackbacks yet.