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

Detail Table CommandTemplate

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mfmz
Top achievements
Rank 1
mfmz asked on 25 May 2009, 01:50 PM
Hi,

How do I get key value of parent table from detail table's Command Template?

Hopefully  I get answer for this question. I did not get none of for my week ago questions.

Code
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1NeedDataSource" OnDetailTableDataBind = "DetailTableDataBind"  > 
        <MasterTableView AutoGenerateColumns="false"  AllowAutomaticInserts="true" DataKeyNames="CompanyID" Name="Company" 
         HierarchyLoadMode="Client">                  
         
        <Columns> 
        <telerik:GridBoundColumn DataField="CompanyID" UniqueName="CompanyID"  Display="false" DataType="System.Int32" >    
         
        </telerik:GridBoundColumn>               
         
        <telerik:GridBoundColumn DataField="CompanyName" UniqueName="CompanyName" HeaderText="Company Name">               
        <ItemStyle Width="100px" /> 
        </telerik:GridBoundColumn>                           
                                                                                                 
        </Columns> 
         
        <DetailTables> 
            <telerik:GridTableView runat="server" DataKeyNames="EmployeeID" AutoGenerateColumns="false" Name="Employee" CommandItemDisplay="Top"  > 
             <CommandItemTemplate > 
             <input type="button" value="Add Employee" id="addE"  onclick="popupAddEmployee('<%# DataBinder.Eval(Container.DataItem, "CompanyID") %>')" /> 
             </CommandItemTemplate> 
             <ParentTableRelation> 
                 <telerik:GridRelationFields DetailKeyField="CompanyID" MasterKeyField="CompanyID" /> 
             </ParentTableRelation> 
              
            <ExpandCollapseColumn Visible="False"
                <HeaderStyle Width="19px" /> 
            </ExpandCollapseColumn> 
             
            <RowIndicatorColumn Visible="False"
               <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
             
            <Columns> 
                <telerik:GridBoundColumn DataField="CompanyID" Display="false" DataType="System.Int32" >    
                 
                </telerik:GridBoundColumn>  
                <telerik:GridBoundColumn DataField="EmployeeID" Display="false" DataType="System.Int32" >    
                 
                </telerik:GridBoundColumn>               
                 
                <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name">               
                <ItemStyle Width="100px" /> 
                </telerik:GridBoundColumn> 
                
                <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name">               
                <ItemStyle Width="100px" /> 
                </telerik:GridBoundColumn> 
                 
                <telerik:GridBoundColumn DataField="TitleId" Display="false" DataType="System.Int32">                     
                </telerik:GridBoundColumn> 
                 
                <telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title" >             
                <ItemStyle Width="100px" /> 
                </telerik:GridBoundColumn>         
                 
                <telerik:GridBoundColumn DataField="BirthDate"  HeaderText="BirthDate" >             
                <ItemStyle Width="100px" /> 
                </telerik:GridBoundColumn> 
                    
                <telerik:GridBoundColumn DataField="ShiftStart" UniqueName="ShiftStart" HeaderText="Shift Start" >             
                <ItemStyle Width="150px" /> 
                </telerik:GridBoundColumn>      
                 
                <telerik:GridBoundColumn DataField="JoinDate" UniqueName="JoinDate" HeaderText="JoinDate" >             
                <ItemStyle Width="150px" /> 
                </telerik:GridBoundColumn>    
                                                                                                 
            </Columns> 
            
             
            </telerik:GridTableView> 
             
        </DetailTables> 
                 
       <%-- <CommandItemTemplate> 
        <input type="button" value="Add Company" id="addC" onclick="popupAddCompany();" /> 
        </CommandItemTemplate>--%> 
                 
        </MasterTableView> 
        <ClientSettings> 
        <ClientEvents OnCommand="OnCommand" OnRowDataBound="OnRowDataBound" OnRowCreated = "OnRowCreated"  
          /> 
        </ClientSettings> 
        </telerik:RadGrid> 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 25 May 2009, 04:43 PM
Hello,

Try the following approach:
'<%# Container.OwnerTableView.ParentItem.GetDataKeyValue("ID").ToString() %>'  

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
mfmz
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or