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

Get Parent Data Item from the child data item

2 Answers 336 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhamed Shafi
Top achievements
Rank 1
Muhamed Shafi asked on 11 Aug 2011, 12:10 PM
Hi there,
        I have a main grid and a parent grid inside the main grid in a nesteview Template. Is there any way to refer the parent GridDataItem in the child grid'd itemDataBound event ? Please find the code below for your reference. Any help would be appreciated
<telerik:RadGridSkin="Office2007"runat="server"ID="rdGd1"ShowFooter="False"
                                AllowSorting="True"AllowPaging="True"   PageSize="10"
                                GridLines="None"
                                <MasterTableViewDataKeyNames="assetNodeID"AutoGenerateColumns="False"Name="MainGrid"
                                    CommandItemDisplay="Top"HierarchyLoadMode="ServerOnDemand"
                                    <CommandItemTemplate
                                        <asp:LabelID="lblHeaderr"runat="server"></asp:Label
                                    </CommandItemTemplate
                                      <Columns
.... 
.... 
..... 
  </Columns
                                    <NestedViewTemplate
    
         <asp:Panel runat="server"ID="InnerContainer"
<telerik:RadGrid id="childGrid" runat="server"  OnItemDataBound="childGrid_ItemDataBound">
 <MasterTableView>
<columns>
.....
....
....
</columns>
 </MasterTableView>
  
  
</telerik:RadGrid ></asp:Panel
                                    </NestedViewTemplate
 <ExpandCollapseColumnVisible="True"
                                    </ExpandCollapseColumn
                                </MasterTableView
                            </telerik:RadGrid>
ProtectedSuchildGrid_ItemDataBound(ByValsource AsObject, ByVale AsTelerik.Web.UI.GridCommandEventArgs)    
            ....   Here Here I need the dataItem details of the parent grid
  EndSub

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Aug 2011, 01:06 PM
Hello Muhamed,

Try the following code snippet to achieve the scenario.
VB:
Protected Sub RadGrid2_ItemDataBound(sender As Object, e As GridItemEventArgs)
   If TypeOf e.Item Is GridDataItem Then
      Dim innergrid As RadGrid = DirectCast(sender, RadGrid)
      Dim nesteditem As GridNestedViewItem = DirectCast(innergrid.NamingContainer, GridNestedViewItem)
      Dim parentItem As GridDataItem = DirectCast(nesteditem.ParentItem, GridDataItem)
      Dim Id As String = parentItem.GetDataKeyValue("assetNodeID").ToString()
    End If
End Sub

Thanks,
Shinu.
0
Muhamed Shafi
Top achievements
Rank 1
answered on 12 Aug 2011, 07:36 AM
Thanks Shinu,
    Its working great!!!
Tags
Grid
Asked by
Muhamed Shafi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Muhamed Shafi
Top achievements
Rank 1
Share this question
or