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

How to access parent relation field on the need datasource of detail table.

2 Answers 238 Views
Grid
This is a migrated thread and some comments may be shown as answers.
giridhar
Top achievements
Rank 1
giridhar asked on 17 Mar 2009, 10:30 AM
Hi All,
   Current I have a Telerik:Grid which has NestedViewTemplate. Inside this NestedViewTemplate I have a DetailTables. Inside the DetailTables. I have Telerik:GridTableView. I have specified ParentTableRelation with DetailKeyFeild and MasterKeyFeild.

This GridTableView is binding data when I expand the row in MatserTable of main grid.

Problem: On code behind of OnNeedDataSource of Grid present in detail table, How to access the value of DataKeyName of main table. I have specified the same key as the MasterKeyFeild also.
To be precise, How to access MasterKeyFeild Value specified in the detail table in OnNeedDataSource. I hope this MasterKeyFeild Value would be obtained from MainGrid automatically.

Posting code for your comfort.

 
<rad:radgrid id="UserGridRegular"
        <MasterTableView  DataKeyNames="ID" DataKeyNames="ID"
                            <NestedViewTemplate> 
                                <Rad:RadGrid ID="nestedgrid" runat="server" OnNeedDataSource="UserGridRegular_NeedDataSource1"
                                    <MasterTableView HierarchyDefaultExpanded="false"  HierarchyLoadMode="ServerBind" EnableNoRecordsTemplate="false" 
                    DataKeyNames="ID,ParentID"
                                        <SelfHierarchySettings ParentKeyName="ParentID" KeyName="ID"></SelfHierarchySettings> 
                                        <DetailTables> 
                                            <Rad:GridTableView DataKeyNames="ID"
                                                <ParentTableRelation> 
                                                    <Rad:GridRelationFields DetailKeyField="ID" MasterKeyField="ID" /> 
                                                </ParentTableRelation> 
                                                <Columns> 
                                                    <Rad:GridTemplateColumn HeaderText="ID" 
                                                        UniqueName="ID"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="Literal7" runat="server" Text='<%# Eval("ID") %>'></asp:Literal> 
                                                        </ItemTemplate> 
                                                    </Rad:GridTemplateColumn>              
                                                    <Rad:GridTemplateColumn HeaderText="ParentID" 
                                                        UniqueName="ParentID"
                                                        <ItemTemplate> 
                                                            <asp:Literal ID="Literal8" runat="server" Text='<%# Eval("ParentID") %>'></asp:Literal> 
                                                        </ItemTemplate> 
                                                    </Rad:GridTemplateColumn>   
                                                </Columns> 
                                            </Rad:GridTableView> 
                                        </DetailTables> 
                                    </MasterTableView> 
                                </Rad:RadGrid> 
                            </NestedViewTemplate> 
                    <Columns> 
                        <Rad:GridTemplateColumn HeaderText="ID" 
                            UniqueName="ID"
                            <ItemTemplate> 
                                <asp:Literal ID="Literal2" runat="server" Text='<%# Eval("ID") %>'></asp:Literal> 
                            </ItemTemplate> 
                        </Rad:GridTemplateColumn>   
                    </Columns> 
        </MasterTableView> 
</rad:radgrid> 
 


2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Mar 2009, 11:48 AM
Hi Giridhar,

One suggestion will be to access the Key value for the row and store it in a public variable while expanding the row of  the main Grid. Once the NeedDataSource event for the Detail table fires you can access the key value from the public variable.

Shinu
0
giridhar
Top achievements
Rank 1
answered on 17 Mar 2009, 11:52 AM
Thanks a lot for the reply.
Tags
Grid
Asked by
giridhar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
giridhar
Top achievements
Rank 1
Share this question
or