views:

32

answers:

1

To make this as simple as I can think to ask, if I have to classes:

Order, OrderType, where an Order has 1 to 1 relationship with OrderType, how can I Bind (List) to a datagrid, and see the desired column/field from OrderType?

When I bind a List to a datagrid, in the Order.OrderType 'field', I just get the name of the OrderType class with a guid. I need to be able to say something like 'use the 'Code' field from the OrderType class.

A: 

This isn't really an nhibernate question, as this problem could come up with any object, regardless of how's it's persisted. What I think you're asking is you want to have a list of orders in a grid, and you want to bind to a property of another property that is a class.

<asp:Gridview ID="gv1" runat="server">
   <Columns>
       <!-- regular properties -->
       <asp:BoundField DataField="Id" HeaderText="Id" />
       <asp:BoundField DataField="CreatedAt" HeaderText="DatePlaced" />

       <!-- property of a property-->
       <asp:TemplateField HeaderText="Order Code">
          <ItemTemplate>
                <asp:Label Text='<%#((Order)Container.DataItem).OrderType.Code %>' runat="server" />
          </ItemTemplate>           
       </asp:TemplateField>
   </Columns>
</asp:Gridview>

Hope that helps.

For WinForms, check out the solutions at http://www.weask.us/entry/winforms-datagridview-databind-complex-type-nested-property

Tim Hoolihan