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

[Solved] NestedViewTemplate parent

1 Answer 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeroen Eikmans
Top achievements
Rank 1
Jeroen Eikmans asked on 11 Jun 2009, 08:28 AM
Hi,

I have a RadGrid with a NestedViewTemplate in a DetailTable in a DetailTable.
So the grid (without columns etc) looks like this :
<telerik:RadGrid ID="customerRadGrid">  
    <MasterTableView DataKeyNames="CustomerID">  
      <DetailTables> 
         <telerik:GridTableView DataKeyNames="ProductID">  
            <ParentTableRelation> 
              <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" /> 
            </ParentTableRelation> 
            <DetailTables>   
              <telerik:GridTableView DataKeyNames="SupplierID">  
                <ParentTableRelation> 
                  <telerik:GridRelationFields DetailKeyField="ProductID" MasterKeyField="ProductID" /> 
                </ParentTableRelation> 
                <NestedViewTemplate> 
                      <asp:Button ID="startButton" runat="server" Text="Start"   
                        onclick="startButton_Click" />                    
                </NestedViewTemplate> 
              </telerik:GridTableView>                
            </DetailTables> 
         </telerik:GridTableView> 
      </DetailTables> 
    </MasterTableView> 
  </telerik:RadGrid> 


In the template there is a button for the user to click.
When the user clicks the button i need to know what the parent row is, so i can get the datakeyvalue of that row.

I tried this by setting the row to selected as soon as the user expands it but since there can be multiple rows expanded this isn't working.

Anybody any ideas?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 11 Jun 2009, 09:26 AM
Hello Roel,

You can try out the following code to achieve the required scenario:
c#:
protected void startButton_Click(object sender, EventArgs e)  
    {  
        Button btn = (Button)sender;  
        GridNestedViewItem nestedviewItem = (GridNestedViewItem)btn.NamingContainer; 
        GridDataItem dataItem = (GridDataItem)nestedviewItem.ParentItem; //to access the parent row 
        string strtxt = dataItem.GetDataKeyValue("SupplierID").ToString(); // to get the datakeyvalue 
    }  

Thanks
Princy.
Tags
Grid
Asked by
Jeroen Eikmans
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or