This is a migrated thread and some comments may be shown as answers.

How do I reference a related table column?

2 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 16 Jul 2011, 08:21 PM
I have a grid tied to an EntityDataSource and can show the columns fine. One of the columns is a guid and I want to show a related table value instead of the guid. I include the related table in the EDS definitions. How do I refernce in the column? The following does not work. Thanks.

<telerik:GridBoundColumn DataField="it.Facility.FacilityName" DataType="System.String"

    FilterControlAltText="Filter Facility column" ReadOnly="True"

    HeaderText="Facility" SortExpression="Facility"

    UniqueName="Facility">
</
telerik:GridBoundColumn>

 

2 Answers, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 17 Jul 2011, 03:03 AM
I'm pretty sure all I need to do is drop the "it." then I can navigate but am unable to try this right now...
0
Genti
Telerik team
answered on 20 Jul 2011, 01:22 PM
Hi Dave,

Thank you for contacting us.

If you are using an EntityDataSource control than you can achieve that kind of referencing if you set the select command in the following:
Select="it.[OrderID], it.Customer.[ContactName]">
And then the BoundColumn would be:
<telerik:GridBoundColumn DataField="ContactName" HeaderText="Name" UniqueName="ContactName" />

Otherwise, if you set the DataSource on the GridNeedDataSource event, then you need to make the referenced table columns public to the grid in the following:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    var lines = from o in DbContext.Orders
                select new
                {
                    OrderID = o.OrderID,
                    ContactName = o.Customer.ContactName
                };
 
    RadGrid1.DataSource = lines;
}

I am also attaching a sample solution that makes use of the Northwind database.


Hope this helps.

Greetings,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Dave
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Genti
Telerik team
Share this question
or