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

How To get the parent GridDataItem from a nested view control

6 Answers 338 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 05 Aug 2011, 12:06 PM
Hi there,
    I have a grid and a button inside the nested view template. What is the way of getting the parent dataitem details in the GridItemCommand event for this button? Have a look at the code below and any help would be higgly appreciated
                            <telerik:RadGrid Skin="Office2007" runat="server" ID="rdGd1" ShowFooter="False"
                                AllowSorting="True" AllowPaging="True"   PageSize="10"
                                GridLines="None">
                                <MasterTableView DataKeyNames="assetNodeID" AutoGenerateColumns="False" Name="MainGrid"
                                    CommandItemDisplay="Top" HierarchyLoadMode="ServerOnDemand">
                                    <CommandItemTemplate>
                                        <asp:Label ID="lblHeaderr" runat="server"></asp:Label>
                                    </CommandItemTemplate>
                                      <Columns>
....
....
.....
  </Columns>
                                    <NestedViewTemplate>
  
         <asp:Panel runat="server" ID="InnerContainer">
      <asp:Button ID="btnView" runat="server" Text="View" CommandName="View" />
 </asp:Panel>
                                    </NestedViewTemplate>
 <ExpandCollapseColumn Visible="True">
                                    </ExpandCollapseColumn>
                                </MasterTableView>
                            </telerik:RadGrid>
  Protected Sub rdGd1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rdGd1.ItemCommand
If e.CommandName = "View" Then
    .... Here I need the current dataItem details of this grid
 End If
  End Sub

Regards
Shafi

6 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Aug 2011, 12:39 PM

Hello,

protected void rdGd1_ItemCommand(object sender, GridCommandEventArgs e)
  {
      if (e.CommandName == "View")
      {
          GridDataItem item = ((GridNestedViewItem)e.Item).ParentItem as GridDataItem;
          string ID = item.GetDataKeyValue("ID").ToString() ;
      }
  }

<telerik:RadGrid Skin="Office2007" runat="server" ID="rdGd1" ShowFooter="False" AllowSorting="True"
           AllowPaging="True" PageSize="10" GridLines="None"
           onitemcommand="rdGd1_ItemCommand" onneeddatasource="rdGd1_NeedDataSource">
           <MasterTableView DataKeyNames="ID" AutoGenerateColumns="False" Name="MainGrid"
               CommandItemDisplay="Top" HierarchyLoadMode="ServerOnDemand">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
               </Columns>
               <NestedViewTemplate>
                   <asp:Panel runat="server" ID="InnerContainer">
                       <asp:Button ID="btnView" runat="server" Text="View" CommandName="View" />
                   </asp:Panel>
               </NestedViewTemplate>
               <ExpandCollapseColumn Visible="True">
               </ExpandCollapseColumn>
           </MasterTableView>
       </telerik:RadGrid>

let me know if any concern.

Thanks,
Jayesh Goyani
0
Muhamed Shafi
Top achievements
Rank 1
answered on 08 Aug 2011, 07:59 AM
Thank you Jayesh
    Its working fine :)
0
Peter
Top achievements
Rank 1
answered on 29 Nov 2012, 01:07 AM
This didn't work for me, I had to use:

((GridDataItem)e.Item).OwnerTableView.ParentItem["Column"].Text 

... as per this article:

http://www.telerik.com/help/aspnet-ajax/grid-traversing-detail-tables-items-in-grid.html

Also see: http://www.telerik.com/help/aspnet-ajax/grid-mastertableview-difference.html
0
Jayesh Goyani
Top achievements
Rank 2
answered on 29 Nov 2012, 09:41 AM
Hello,

Can you please provide your Radgrid markup (.aspx page code)?

Thanks,
Jayesh Goyani
0
L
Top achievements
Rank 1
answered on 17 Jun 2013, 07:40 PM
Hi,

I saw your answer and maybe you can help me with the question I posted today in this link.

http://www.telerik.com/community/forums/aspnet-ajax/grid/find-the-parent-of-the-parent-in-hierarchy-grid.aspx

Thanks in advance
0
L
Top achievements
Rank 1
answered on 17 Jun 2013, 07:53 PM
This was what I was looking for:
GridDataItem parentItem = (GridDataItem)e.DetailTableView.ParentItem.OwnerTableView.ParentItem;

I answered it myself.


Thanks anyway.
Tags
Grid
Asked by
Muhamed Shafi
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Muhamed Shafi
Top achievements
Rank 1
Peter
Top achievements
Rank 1
L
Top achievements
Rank 1
Share this question
or