This is a migrated thread and some comments may be shown as answers.
Get DataKeyValues from child ItemCommand event in NestedViewTemplate
3 Answers 155 Views
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 2
Jose asked on 16 Nov 2010, 09:45 PM
Hello,

I've seen a lot of examples to access to DataKeyValues from DetailTables, but I cannot find an example about doing the same in NestedViewTemplates.

Here is my RadGrid:

<telerik:RadGrid ID="ListGrid" runat="server" AllowFilteringByColumn="True"
     AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
     GridLines="None" ShowStatusBar="True" ShowGroupPanel="True"
     onneeddatasource="ListGrid_NeedDataSource"
     onitemcommand="ListGrid_ItemCommand">
 
     <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"
         AllowDragToGroup="True">
         <Selecting AllowRowSelect="True" />
     </ClientSettings>
 
     <MasterTableView DataKeyNames="CustomerId" CommandItemDisplay="Top">
         <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
 
         <RowIndicatorColumn>
             <HeaderStyle Width="20px"></HeaderStyle>
         </RowIndicatorColumn>
 
         <ExpandCollapseColumn>
             <HeaderStyle Width="20px"></HeaderStyle>
         </ExpandCollapseColumn>
 
         <NestedViewTemplate>
             <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap">
                 <telerik:RadTabStrip runat="server" ID="CustomersTabStrip" MultiPageID="CustomersMultipage" SelectedIndex="0">
                     <Tabs>
                         <telerik:RadTab runat="server" Text="Contacts" PageViewID="ContactsPageView">
                         </telerik:RadTab>
                         <telerik:RadTab runat="server" Text="Addresses" PageViewID="AddressesPageView">
                         </telerik:RadTab>
                     </Tabs>
                 </telerik:RadTabStrip>
                 <telerik:RadMultiPage runat="server" ID="CustomersMultipage" SelectedIndex="0" RenderSelectedPageOnly="false">
                     <telerik:RadPageView runat="server" ID="ContactsPageView">
                         <telerik:RadGrid runat="server" ID="ContactsGrid" AllowSorting="true" DataKeyNames="ContactId"
                             onneeddatasource="ContactsGrid_NeedDataSource"
                             onitemcommand="ContactsGrid_ItemCommand">
                             <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true"
                                 DataKeyNames="ContactId" PageSize="5" HierarchyLoadMode="ServerOnDemand" CommandItemDisplay="Top">
                                 <Columns>
                                     <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                                         Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                                         UniqueName="EditButton" ImageUrl="~/Images/Edit.png" CommandName="Edit">
                                         <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
                                     </telerik:GridButtonColumn>
                                     <telerik:GridBoundColumn DataField="ContactId" HeaderText="Id"
                                         UniqueName="ContactId" Visible="false">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Full Name" DataField="FullName" UniqueName="FullName">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Position" DataField="Position" UniqueName="Position">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Contact Type" DataField="ContactType.Description" UniqueName="ContactType">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridHyperLinkColumn DataNavigateUrlFields="Email" DataNavigateUrlFormatString="mailto:{0}"
                                         DataTextField="Email" HeaderText="Email" UniqueName="Email" Groupable="false"
                                         AllowFiltering="false">
                                     </telerik:GridHyperLinkColumn>
                                     <telerik:GridBoundColumn HeaderText="Phone" DataField="Phone" UniqueName="Phone">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Mobile" DataField="Mobile" UniqueName="Mobile">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                                         Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                                         UniqueName="DeleteButton" ImageUrl="~/Images/Delete.png" CommandName="Delete"
                                         ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?" ConfirmTitle="Delete record..."
                                         ConfirmDialogHeight="130px">
                                         <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
                                     </telerik:GridButtonColumn>
                                 </Columns>
                             </MasterTableView>
                         </telerik:RadGrid>
                     </telerik:RadPageView>
                     <telerik:RadPageView runat="server" ID="AddressesPageView">
                         <telerik:RadGrid runat="server" ID="AddressesGrid" AllowSorting="true" DataKeyNames="AddressId"
                             onneeddatasource="AddressesGrid_NeedDataSource"
                             onitemcommand="AddressesGrid_ItemCommand">
                             <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true"
                                 DataKeyNames="AddressId" PageSize="5" HierarchyLoadMode="ServerOnDemand" CommandItemDisplay="Top">
                                 <Columns>
                                     <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                                         Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                                         UniqueName="EditButton" ImageUrl="~/Images/Edit.png" CommandName="Edit">
                                         <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
                                     </telerik:GridButtonColumn>
                                     <telerik:GridBoundColumn DataField="AddressId" HeaderText="Id"
                                         UniqueName="AddressId" Visible="false">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Address Type" DataField="AddressType" UniqueName="AddressType">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Full Address" DataField="FullAddress" UniqueName="FullAddress">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Zip Code" DataField="ZipCode" UniqueName="ZipCode">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="City" DataField="City" UniqueName="City">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Province" DataField="Province" UniqueName="Province">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridBoundColumn HeaderText="Country" DataField="Country" UniqueName="Country">
                                     </telerik:GridBoundColumn>
                                     <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                                         Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                                         UniqueName="DeleteButton" ImageUrl="~/Images/Delete.png" CommandName="Delete"
                                         ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?" ConfirmTitle="Delete record..."
                                         ConfirmDialogHeight="130px">
                                         <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
                                     </telerik:GridButtonColumn>
                                 </Columns>
                             </MasterTableView>
                         </telerik:RadGrid>
                     </telerik:RadPageView>
                 </telerik:RadMultiPage>
             </asp:Panel>
         </NestedViewTemplate>
 
         <Columns>
             <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                 Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                 UniqueName="EditButton" ImageUrl="~/Images/Edit.png" CommandName="Edit">
                 <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
             </telerik:GridButtonColumn>
             <telerik:GridImageColumn AllowFiltering="False" AllowSorting="False"
                 DataAlternateTextField="Name" DataImageUrlFields="Logo"
                 DataImageUrlFormatString="~/Images/Customers/{0}" Groupable="False"
                 HeaderText="Logo" ImageHeight="64px" ImageWidth="64px" ShowSortIcon="False"
                 UniqueName="Logo" ItemStyle-Width="75px">
                 <ItemStyle Width="75px" />
             </telerik:GridImageColumn>
             <telerik:GridBoundColumn DataField="CustomerId" HeaderText="Id"
                 UniqueName="CustomerId" Visible="false">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Name" HeaderText="Name"
                 UniqueName="Name">
             </telerik:GridBoundColumn>
             <telerik:GridHyperLinkColumn DataNavigateUrlFields="Web"
                 DataNavigateUrlFormatString="{0}" DataTextField="Web"
                 HeaderText="Web" UniqueName="Web" Target="_blank" Groupable="false"
                 AllowFiltering="false">
             </telerik:GridHyperLinkColumn>
             <telerik:GridBoundColumn DataField="Group.Name" HeaderText="Group"
                 UniqueName="Group">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="AccountManager.FullName" HeaderText="Acct. Manager"
                 UniqueName="AccountManager">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="SIC.Description" HeaderText="SIC"
                 UniqueName="SIC">
             </telerik:GridBoundColumn>
             <telerik:GridCheckBoxColumn DataField="IsProspect" HeaderText="Prospect"
                 UniqueName="IsProspect">
             </telerik:GridCheckBoxColumn>
             <telerik:GridButtonColumn ButtonType="ImageButton" Reorderable="False"
                 Resizable="False" ShowFilterIcon="False" ShowSortIcon="False"
                 UniqueName="DeleteButton" ImageUrl="~/Images/Delete.png" CommandName="Delete"
                 ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?" ConfirmTitle="Delete record..."
                 ConfirmDialogHeight="130px">
                 <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
             </telerik:GridButtonColumn>
         </Columns>
 
     </MasterTableView>
 
     <PagerStyle Mode="NextPrevAndNumeric" Position="Bottom" />
 
     <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
 
 </telerik:RadGrid>

How can I get parent DataKeyValues from a child ItemCommand event? I need the CustomerId value in order to pass this parameter to another page.

Any idea?
Thanks a lot in advanced,
Jose

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Nov 2010, 03:46 PM
Hi Jose,

Here is a help article which explains how to extract primary key value for parent item in hierarchy on Update/Insert. Go through it and see if it helps.
Extracting primary key value for parent item in hierarchy on Update/Insert

Sincerely yours,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jose
Top achievements
Rank 2
answered on 17 Nov 2010, 04:40 PM
Hi Pavlina,

Thank you very much for your support.
Before posting my question I was reading this support document and I tried implementing it, but when I run this code parentItem always is null.

If you check my code, I think that this may be because the child grid is inside a MultiPage control, inside a RadTabStrip control, inside an panel.

Any idea?
Regards
Jose
0
Accepted
Pavlina
Telerik team
answered on 19 Nov 2010, 05:09 PM
Hello Jose,

To get the parent item's data key value you can use the following approach:
C#:
((GridNestedViewItem)e.PageView.MultiPage.NamingContainer).ParentItem.GetDataKeyValue("YourDataKeyID");

I hope this helps.

Sincerely yours,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Jose
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Jose
Top achievements
Rank 2
Share this question
or