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

strange error when using SelfHierarchySettings

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 16 Jul 2008, 06:46 AM
I've bound my grid to an entity collection derived from a View.  The view is self referencing and I'd like the grid to represent that parent-child relationship.  The top level seems to acting correctly, but when I try and expand a top level node, I get this error.

"Parent table relation set, but no corresponding data-key name  found."

I've checked all the obvious, but alas, I can't find the problem.

 <telerik:RadGrid runat="server" id="grdClients"  
        OnNeedDataSource="grdClients_NeedDataSource" 
        Skin="Default2006" 
        AutoGenerateColumns="False" 
        AllowPaging ="True" 
        AllowSorting="True" 
        PageSize="8"  
        GridLines="None"  
        ShowStatusBar="False" 
        DataKeyNames="Id, SuperClientId" > 
         
        <ExportSettings> 
            <Excel Format="Html" /> 
        </ExportSettings> 
         
        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> 
             
        <ClientSettings AllowExpandCollapse="true" />  
     
        <MasterTableView> 
         
            <SelfHierarchySettings ParentKeyName="Id" KeyName="SuperClientId" /> 
               
            <Columns> 
                <telerik:GridHyperLinkColumn 
                    DataTextField="Id" 
                    DataTextFormatString="edit"  
                    UniqueName="colEditbasePage"  
                    DataNavigateUrlFormatString="editClient.aspx?id={0}"  
                    DataNavigateUrlFields="id"
                </telerik:GridHyperLinkColumn> 
                <telerik:GridHyperLinkColumn 
                    DataTextField="Id" 
                    DataTextFormatString="deactivate"  
                    UniqueName="colDeactivateClient"  
                    DataNavigateUrlFormatString="?deactivateid={0}"  
                    DataNavigateUrlFields="Id"
                </telerik:GridHyperLinkColumn> 
                 
                <telerik:GridBoundColumn 
                    DataField="CompanyName" 
                    DataType="System.String" 
                    HeaderText="First Name" 
                    SortExpression="CompanyName" 
                    UniqueName="colCompanyName" > 
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn 
                    DataField="City" 
                    DataType="System.String" 
                    HeaderText="City" 
                    SortExpression="City" 
                    UniqueName="colCity" > 
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn 
                    DataField="Country" 
                    DataType="System.String" 
                    HeaderText="Country" 
                    SortExpression="Country" 
                    UniqueName="colCountry" > 
                </telerik:GridBoundColumn> 
                 
                <telerik:GridTemplateColumn HeaderText="Roles I fill"
                     <ItemTemplate> 
                        <table cellpadding="1" cellspacing="1" class="customTable"
                            <tr> 
                                <td style="width: 50%"
                                    <%# getRoleIndicator((int)DataBinder.Eval(Container.DataItem, "Id"), Settings.Default.role_clientCGC)%> 
                                </td> 
                                <td style="width: 50%"
                                    <%# getRoleIndicator((int)DataBinder.Eval(Container.DataItem, "Id"), Settings.Default.role_clientCC)%> 
                                </td> 
                            </tr> 
                        </table> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                 
                <telerik:GridBoundColumn 
                    DataField="NumOfRequestsBought" 
                    DataType="System.Int32" 
                    HeaderText="Number of Requests Purchased" 
                    SortExpression="NumOfRequestsBought" 
                    UniqueName="colNumOfRequestsBought" > 
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn 
                    DataField="NumOfRequestsUsed" 
                    DataType="System.Int32" 
                    HeaderText="Number of Requests Used" 
                    SortExpression="NumOfRequestsUsed" 
                    UniqueName="colNumOfRequestsUsed" > 
                </telerik:GridBoundColumn> 
                 
                <telerik:GridCheckBoxColumn 
                    DataField="PurchasedApprovals" 
                    HeaderText="Purchased Approvals"  
                    AllowSorting="true" 
                    UniqueName="colPurchasedApprovals" > 
                </telerik:GridCheckBoxColumn> 
                <telerik:GridCheckBoxColumn 
                    DataField="PurchasedAgreements" 
                    HeaderText="Purchased Agreements"  
                    AllowSorting="true" 
                    UniqueName="colPurchasedAgreements" > 
                </telerik:GridCheckBoxColumn> 
                                     
            </Columns> 
        </MasterTableView> 
         
    </telerik:RadGrid> 


protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                Page.Title = "GlobeSpec | clients"
 
                Page.Form.DefaultFocus = this.txbFilterGrid.ClientID; 
                Page.Form.DefaultButton = this.btnFilterGrid.UniqueID; 
 
                grdClients.MasterTableView.FilterExpression = "SuperClientID = 0 OR SuperClientID IS NULL"
            } 
        } 
 
        protected void cmdExcel_Click(object sender, EventArgs e) 
        { 
            this.grdClients.ExportSettings.ExportOnlyData = true
            this.grdClients.ExportSettings.IgnorePaging = true
            this.grdClients.MasterTableView.ExportToExcel(); 
        } 
 
        protected void grdClients_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
        { 
            this.grdClients.DataSource = null
 
            VClientsGridCollection coll = new VClientsGridCollection(); 
            coll.LoadAll(); 
 
            if (!string.IsNullOrEmpty(this.txbFilterGrid.Text.Trim())) 
            { 
                //coll.Filter += " AND CompanyName Like '" + this.txbFilterGrid.Text.Trim() + @"%'"; 
                coll.Filter = "CompanyName Like '" + this.txbFilterGrid.Text.Trim() + @"%'"; 
            } 
 
            coll.Sort = "CompanyName"
 
            this.grdClients.DataSource = coll
        } 
 
 
        protected string getRoleIndicator(int clientId, string roleName) 
        { 
            Person me = (Person) Session["User"]; 
 
            l = new Lookup(); 
            l.Query.Where(l.Query.LookupName.Like(roleName.Trim())).Select("Id"); 
            l.Query.Load(); 
 
            pc = new PersonClient(); 
            pc.Query.Where(pc.Query.ClientId.Equal(clientId), 
                           pc.Query.RoleId.Equal(l.Id), 
                           pc.Query.PersonId.Equal(me.Id)); 
             
            if(pc.Query.Load()) 
            { 
                if (roleName.Equals(Settings.Default.role_clientCGC.ToString())) 
                { 
                    return "CGC"; 
                } 
                else if (roleName.Equals(Settings.Default.role_clientCC.ToString())) 
                { 
                    return "CC"; 
                } 
            } 
 
            return string.Empty; 
        } 
 
        protected void btnFilterGrid_Click(object sender, EventArgs e) 
        { 
            this.grdClients.DataSource = null
 
            VClientsGridCollection coll = new VClientsGridCollection(); 
            coll.LoadAll(); 
 
            if (!string.IsNullOrEmpty(this.txbFilterGrid.Text.Trim())) 
            { 
                coll.Filter = "CompanyName Like '" + this.txbFilterGrid.Text.Trim() + @"%'"; 
            } 
 
            coll.Sort = "CompanyName"
 
            this.grdClients.DataSource = coll
            this.grdClients.DataBind(); 
        } 


Any help or ideas would be greatly appreciated..


3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 16 Jul 2008, 01:23 PM
Hello Paul,

When defining a Self-referencing hierarchy in RadGrid, you need to specify DataKeyNames for the MasterTableView, but not for RadGrid, as this property is not inherited in the hierarchy. Please set DataKeyNames="Id, SuperClientId" for the MasterTableView.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Paul
Top achievements
Rank 1
answered on 16 Jul 2008, 05:40 PM
Thank You.  That worked great.

Is there a way to set the width on Nested Tables using the SelfHierarchySettings node?  I tried to add a 'width' propertiy to this markup but it doesn't like that ...
<SelfHierarchySettings ParentKeyName="SuperClientId" KeyName="Id" MaximumDepth="0" /> 

Is there a way to do this programmatically?

Thanks,
Paul
0
Sebastian
Telerik team
answered on 17 Jul 2008, 06:47 AM
Hi Paul,

The width set for the master table in the grid will be automatically cloned for the nested levels in self-referencing grid. In case your goal is to align the columns in self-referencing hierarchy, consider the approach presented in this knowledge base article:

http://www.telerik.com/support/kb/article/b454K-khh-b454T-bha-b454c-bha.aspx

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Veli
Telerik team
Paul
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or