Show data from related entity in gridview

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 03-Aug-2007 13:00:12   

Hi,

I have the following question:

I have a Project, with ProjectType (1:m relation) I also have a table called ProjectType, with at least ProjectTypeID and Description.

I have a entitycollection of projectentites and get related projectTypeinfo also

So I can do for example this: myProjects[0].ProjectType.Description to read the description.

Now I Bind this collection using the llblgendatasource to a datagridview.

Is it possible now to bind the a column to this projecttype.description field, or if not bind, just showing this value then?

Best regards,

  • G.I.
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 03-Aug-2007 16:26:59   

Here is an example of showing Products and binding to the Category.CategoryName:

'<%# DataBinder.Eval(Container.DataItem, "Category.CategoryName")%>'

As shown here:

                        <asp:TemplateField HeaderText="Category" SortExpression="CategoryId">
                            <ItemTemplate>
                                <asp:Label ID="Category" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Category.CategoryName")%>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="Categories" runat="server" DataSourceID="CategoriesDS" DataTextField="CategoryName"
                                    DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>' />
                            </EditItemTemplate>
                        </asp:TemplateField>

Tip: You should use a PrefetchPath (to projectType) in the fetch method.