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

Can't Display lookup data on GridView

9 Answers 188 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jay
Top achievements
Rank 1
jay asked on 23 Jun 2010, 04:25 PM
Hello,
I have tried using [Include] without any luck.
I am trying to show the EmployeeID, LastName, FirstName (amongst other data in other lookup tables) in a gridview.
I have attached an image of the a section of the model object.

(a) is a section of my model - which shows a 1 to many relationship between Employee and Contact.
The employee table is self-referencing. I have edited the Employees in the Employee entity diagram to be DirectReports and Manager.
The Contact table can have multiple records for the same EmployeeID - one for the employee themselves and one for each of their other contacts like spouses.

(b) Section of my metadata class

  internal sealed class EmployeeMetadata 
        { 
 
            // Metadata classes are not meant to be instantiated. 
            private EmployeeMetadata() 
            { 
            } 
                       
            [Include] 
            [Display(Order = 0)] 
            public EntityCollection<Contact> Contacts { get; set; } 

(c) My GetEmployee procedure

   public IQueryable<Employee> GetEmployees() 
        { 
            return this.ObjectContext.Employees.Include("Contacts").Where(e => e.CurrentFlag == true).OrderBy(e => e.EmployeeID);  
        } 

(d) My DDS declaration
<riaControls:DomainDataSource AutoLoad="True"  Height="0" LoadedData="EmployeeDDS_LoadedData"   d:DesignData="{d:DesignInstance domain:Employee, CreateList=true}"  
                                                    Name="EmployeeDDS" QueryName="GetEmployeesQuery" Width="0" > 
                                                                      <riaControls:DomainDataSource.DomainContext> 
                                                                                <domain:hrContext /> 
                                                                        </riaControls:DomainDataSource.DomainContext> 
   </riaControls:DomainDataSource> 

(e) and finally, my gridview declaration
 <telerik:RadGridView Name="EmployeeRadGridView"  ItemsSource="{Binding ElementName=EmployeeDDS, Path=Data}"  
                                                             Width="717" Height="333" AutoGenerateColumns="False" RowHeight="15" FontFamily="Lucida Sans Unicode"   
                                                               RowLoaded="EmployeeRadGridView_RowLoaded" DataLoading="EmployeeRadGridView_DataLoading"  Background="Azure"  
                                                             SelectionChanged="EmployeeRadGridView_SelectionChanged"     
                                                             AlternateRowBackground="LightSteelBlue" > 
                                            
 
                                        <telerik:RadGridView.Columns> 
                                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=EmployeeID}" Header="EmployeeID" Width="100"
                                                <telerik:GridViewDataColumn.AggregateFunctions> 
                                                    <telerik:CountFunction Caption="Count:" /> 
                                                </telerik:GridViewDataColumn.AggregateFunctions> 
                                            </telerik:GridViewDataColumn> 
 
                                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=LastName}" Header="LastName" Width="100" IsReadOnly="True" /> 
                                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=NationalIDNumber}" Header="NationalIDNumber" Width="100"/>    
                                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=LoginID}" Header="LoginID" Width="100"/>   
                                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=TitleID}" Header="Title"/> 
                                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=HireDate}" Header="HireDate" DataFormatString="{}{0:d}" > 
                                            </telerik:GridViewDataColumn> 
 
                                        </telerik:RadGridView.Columns> 
                                            <telerik:RadGridView.ChildTableDefinitions> 
                                                <telerik:GridViewTableDefinition> 
                                                    <telerik:GridViewTableDefinition.Relation> 
                                                        <telerik:TableRelation IsSelfReference="True"
                                                            <telerik:TableRelation.FieldNames> 
                                                                <telerik:FieldDescriptorNamePair  
                                                                    ParentFieldDescriptorName="EmployeeID"  
                                                                    ChildFieldDescriptorName="ReportsToID"/> 
                                                            </telerik:TableRelation.FieldNames> 
                                                        </telerik:TableRelation> 
                                                    </telerik:GridViewTableDefinition.Relation> 
                                                </telerik:GridViewTableDefinition> 
                                            </telerik:RadGridView.ChildTableDefinitions> 
        </telerik:RadGridView> 
 


Grateful if someone could point out to me what I am missing. This is my 3rd day fighting over this. 
HOW DO I GET TO SEE THE LASTNAMES AND FIRSTNAMES ON THE GRID???

Thanks !
J

9 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 28 Jun 2010, 04:02 PM
Hello jay,

Probably you stumbled upon the problem described here.

I have attached a sample VS 2010 solution to this thread as well.

Sincerely yours,
Veskoni
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
jay
Top achievements
Rank 1
answered on 28 Jun 2010, 04:55 PM
Thanks Veskoni.
The solution did not quite help me. My main aim is to show the LastName (which is taken from an INCLUDED lookup entitiy -Contact) in the GridView alongside EmployeeID, LoginId, HireDate (which come from the main Employee entity).
I have a normalized database that stores names in only one table - Contact. It would have been easier if the Lasname was a column in the Employee table, but I opted for the current database structure.

J
0
jay
Top achievements
Rank 1
answered on 29 Jun 2010, 01:36 AM
Hi Veskoni,

The attached image shows what I am trying to achieve. 
In this scenario, Employees 2,4,5,6 & 7 report to Employee 1, and can be seen when I expand the + box at the left. This bit is working great as i can clearly see which employee has direct reports and who they are. My ONLY current need is to populate the LastName column in the header section of the grid.

How can I modify my code to make LastName, which comes from a Contact lookup entity, show up? As I said earlier, there is a 1 to many relationship between the Employee and Contact entities. For a give record in Employee, there can be several records in Contact, the first of which will have a contactType of 'Self'. Other records can be Spouse, NextofKin...........

Thanks!
J

0
Veselin Vasilev
Telerik team
answered on 01 Jul 2010, 09:57 AM
Hi jay,

I have updated my project to reflect the things you need. I have a table Orders and another table OrderDetails. I am showing the Max unit price from the Order Details table into the root gridview (which shows the orders).
Note the Order.cs class which defines the MaxUnitPrice property.

Hope this helps you achieve the same goal.

Regards,
Veskoni
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
jay
Top achievements
Rank 1
answered on 01 Jul 2010, 02:28 PM
Thanks Veskoni,

This is very close. Can I assume that it is not possible to databind to the LastName field using something like:

  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=LastName}" Header="LastName" Width="100" IsReadOnly="True" />   


OR

 <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Contact.LastName}" Header="LastName" Width="100" IsReadOnly="True" />
even after specifying the INCLUDE?

I was able to run your updated app, and see the lookup value in the MaxUnitPrice column. This is great! 
However, when I tried to sort by MaxUnitPrice I get the following error:  {System.ServiceModel.DomainServices.Client.DomainOperationException: Load operation failed for query 'GetOrders'. The specified type member 'MaxUnitPrice' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.}

Any suggestions?
Thanks !
J


0
jay
Top achievements
Rank 1
answered on 01 Jul 2010, 05:54 PM
Thanks, Veskoni !
A suggestion from Pavel fixed it. I am using GridComboboxes.

Regards,
J
0
Jonx
Top achievements
Rank 2
answered on 29 Aug 2010, 04:41 PM
Hello Jay,
May I ask you how you solved your problem?
I have almost the same trouble...

I'm trying to sort on a computer property and this gives me the same error...

Any hints on that? Tanks...

using System.Runtime.Serialization;
namespace AWeb
{
    public partial class ProgramDetail
    {
        [DataMember]
        public string FormattedShowName
        {
            get
            {
                if (string.IsNullOrWhiteSpace(this.ShowName))
                {
                    return this.Title;
                }
                else
                {
                    return string.Format("{0} S{1:00}E{2:00}", this.ShowName, this.Season, this.Episode);
                }
            }
            set { }
        }
    }
}
0
jay
Top achievements
Rank 1
answered on 04 Sep 2010, 02:14 AM
HI John,
Sorry for replying so late. I just saw your post.

Please take a look at Pavel's suggestion on July 1st on the this page:
http://www.telerik.com/community/forums/silverlight/gridview/binding-lookup-values.aspx


Regards,
J
0
Jonx
Top achievements
Rank 2
answered on 04 Sep 2010, 11:57 PM
Hello Jay,
Thank you exactly what I needed ;)
Tags
GridView
Asked by
jay
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
jay
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Share this question
or