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

RadGrid Hierarchy values

3 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff Wickersham
Top achievements
Rank 1
Jeff Wickersham asked on 02 May 2013, 01:00 AM
I have the following telerik grid and need to pass the data value from the nested table into the ItemCommand so when
the user clicks the grid button the code is executed I am stuck on where to go with this

<telerik:RadGrid ID="grdRegions" runat="server" Skin="Metro" AllowCustomSorting="True"
                ShowHeader="True" PageSize="10" ShowGroupPanel="False"     OnItemCommand="grdRegions_ItemCommand"
                ShowStatusBar="True" AutoGenerateColumns="False"
                AllowSorting="True" AllowPaging="True" DataSourceID="RegionDS" Width="500px">
                <PagerStyle Mode="Slider" />
                <MasterTableView DataSourceID="RegionDS" DataKeyNames="RegionCode" AllowMultiColumnSorting="True" Width="100%">

                    <DetailTables>
                        <telerik:GridTableView runat="server" DataKeyNames="RegionCode,DealerId" DataSourceID="DealerDS" AllowFilteringByColumn="True" >
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="RegionCode" MasterKeyField="RegionCode"  />
                            </ParentTableRelation>
                            <Columns>
                                <telerik:GridBoundColumn SortExpression="DealerId" HeaderText="Dealer" HeaderButtonType="TextButton"
                                    DataField="Dealer" UniqueName="DealerId">
                                </telerik:GridBoundColumn>

                                <telerik:GridBoundColumn SortExpression="RegionCode" HeaderText="FDAF Region Code" HeaderButtonType="TextButton"
                                    DataField="RegionCode" UniqueName="RegionCode" AllowFiltering="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn SortExpression="DealerId" HeaderText="DealerId" HeaderButtonType="TextButton"
                                    DataField="DealerId" UniqueName="Dealer">
                                </telerik:GridBoundColumn>
                               <telerik:GridTemplateColumn ItemStyle-Width="22px" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:ImageButton ID="EditDealer" runat="server" AlternateText="Edit Dealer" ToolTip="Edit Dealer"
                                        ImageUrl="Images/edit.png" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.DealerId")%>'
                                        CommandName="EditDealer" CausesValidation="false" />
                                </ItemTemplate>
                                <ItemStyle Width="22px"></ItemStyle>
                            </telerik:GridTemplateColumn>
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                    <Columns>
                        <telerik:GridBoundColumn SortExpression="RegionName" HeaderText="FDAF Region" HeaderButtonType="TextButton"
                            DataField="RegionName" UniqueName="RegionName" AllowFiltering="False">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn SortExpression="RegionCode" HeaderText="FDAF Region Code" HeaderButtonType="TextButton"
                            DataField="RegionCode" UniqueName="RegionCode">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn SortExpression="RegionDealerCount" HeaderText="Dealers In Region" HeaderButtonType="TextButton"
                            DataField="RegionDealerCount" UniqueName="RegionDealerCount" AllowFiltering="False">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>






                     protected void grdRegions_ItemCommand(object sender, GridCommandEventArgs e)
                        {
                            objDealerDL.DealerId = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["DealerId"].ToString());
                            GridDataItem item = (GridDataItem)e.Item;                       
                            if (e.CommandName == "EditDealer")
                            {
                                try
                                {
                                  do work
                                }
                                catch (Exception ex)
                                {

                                }
                            }
                        }

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 06 May 2013, 12:24 PM
Hi Jeff,

You can access the item as well as the parent item of the clicked button container:
<telerik:GridTableView ... Name="Orders">
C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.Item.OwnerTableView.Name == "Orders" && e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        string dataKeyID = dataItem.GetDataKeyValue("OrderID").ToString();
 
        GridNestedViewItem nestedViewItem = dataItem.OwnerTableView.NamingContainer as GridNestedViewItem;
        GridDataItem parentItem = nestedViewItem.ParentItem as GridDataItem;
        string parentDataKeyID = parentItem.GetDataKeyValue("CustomerID").ToString();
    }
}

Additionally, you can refer to this article for accessing the cell contents of the item:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Hope this helps.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Sumathi
Top achievements
Rank 1
answered on 06 Apr 2016, 09:37 PM

Hi,

I have a radgrid with 3 levels of hierarchy. I am doing a programming binding using NeedDataSource and DetailsTableBind events. 

I want to get all data at once and bind it so that I don't go to the database each time the expand is clicked on each level. Right now, I am not sure how to go about it. Attached the code.



<telerik:RadGrid ID="gridComplianceSummary" runat="server" AutoGenerateColumns="false"
                Skin="Office2007" AllowPaging="True" AllowSorting="True" GroupPanelPosition="Top"
                PagerStyle-Mode="NextPrevAndNumeric" OnNeedDataSource="gridComplianceSummary_NeedDataSource"
                ResolvedRenderMode="Classic" ExportSettings-OpenInNewWindow="true" OnHTMLExporting="gridComplianceSummary_Exporting"
                OnPageIndexChanged="grid_PageIndexChanged" OnPageSizeChanged="grid_PageSizeChanged"
                OnDetailTableDataBind="grid_DetailTableDataBind">
                <HeaderStyle Font-Bold="true" HorizontalAlign="Center" Font-Size="Smaller" Font-Names="Verdana" />
                <ItemStyle Font-Size="Smaller" />
                <AlternatingItemStyle Font-Size="Smaller" />
                <ExportSettings OpenInNewWindow="true" ExportOnlyData="true" Excel-Format="Xlsx">
                </ExportSettings>
                <MasterTableView DataKeyNames="Division_Code">
                    <DetailTables>
                        <telerik:GridTableView DataKeyNames="Division_Code,Zone_Code" Name="Zones">
                            <Columns>
                                <telerik:GridBoundColumn DataField="Zone_Code" ItemStyle-Width="18px" AllowSorting="true"
                                    AllowFiltering="false" SortExpression="Zone_Code" UniqueName="ZoneCode" HeaderText="Zone">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Total" AllowSorting="true" AllowFiltering="false"
                                    UniqueName="Totals" HeaderText="# of s" SortExpression="Totals"
                                    ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="TotalCompliant" AllowSorting="true"
                                    AllowFiltering="false" UniqueName="Compliant" HeaderText="# of Compliant "
                                    SortExpression="Compliant" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="PercentageCompliance" AllowSorting="true"
                                    AllowFiltering="false" UniqueName="CompliancePercent" HeaderText="% of  Compliance"
                                    SortExpression="CompliancePercent" ItemStyle-HorizontalAlign="Right"
                                    ItemStyle-Width="100px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Boxs" AllowSorting="true" AllowFiltering="false"
                                    UniqueName="Boxs" HeaderText="# of Boxs (Post+Pre)" SortExpression="Boxs"
                                    ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="BoxsCompliant" AllowSorting="true" AllowFiltering="false"
                                    UniqueName="BoxsCompliant" HeaderText="# of Compliant Boxs" SortExpression="BoxsCompliant"
                                    ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="PercentageBoxsCompliant" AllowSorting="true"
                                    AllowFiltering="false" UniqueName="BoxsCompliantPercent" HeaderText="% Compliant Boxs"
                                    SortExpression="BoxsCompliantPercent" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <DetailTables>
                                <telerik:GridTableView DataKeyNames="Division_Code,Zone_Code,SalesDistrictCode" Name="Districts">
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="SalesDistrictCode" ItemStyle-Width="18px" AllowSorting="true"
                                            AllowFiltering="false" SortExpression="SalesDistrictCode" UniqueName="SalesDistrictCode"
                                            HeaderText="District">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="Total" AllowSorting="true" AllowFiltering="false"
                                            UniqueName="Total" HeaderText="# of " SortExpression="Total"
                                            ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="TotalCompliant" AllowSorting="true"
                                            AllowFiltering="false" UniqueName="Compliant" HeaderText="# of Compliant "
                                            SortExpression="Compliant" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="PercentageCompliance" AllowSorting="true"
                                            AllowFiltering="false" UniqueName="CompliancePercent" HeaderText="% of  Compliance"
                                            SortExpression="CompliancePercent" ItemStyle-HorizontalAlign="Right"
                                            ItemStyle-Width="100px">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="Boxs" AllowSorting="true" AllowFiltering="false"
                                            UniqueName="Boxs" HeaderText="# of Boxs (Post+Pre)" SortExpression="Boxs"
                                            ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="BoxsCompliant" AllowSorting="true" AllowFiltering="false"
                                            UniqueName="BoxsCompliant" HeaderText="# of Compliant Boxs" SortExpression="BoxsCompliant"
                                            ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="PercentageBoxsCompliant" AllowSorting="true"
                                            AllowFiltering="false" UniqueName="BoxsCompliantPercent" HeaderText="% Compliant Boxs"
                                            SortExpression="BoxsCompliantPercent" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                    <DetailTables>
                                        <telerik:GridTableView DataKeyNames="Division_Code,Zone_Code,SalesDistrictCode,StoreCode" Name="Stores" HierarchyLoadMode="Client">
                                            <Columns>
                                                <telerik:GridHyperLinkColumn DataNavigateUrlFields="Link_Code" UniqueName="Store"
                                                    AllowFiltering="false" Target="blank" HeaderText="Store Code" ItemStyle-Width="30px"
                                                    DataNavigateUrlFormatString="Report.aspx?LINK={0}&MID=14661" DataTextField="Store_Code">
                                                </telerik:GridHyperLinkColumn>
                                                <telerik:GridBoundColumn HeaderText="Store Name" DataField="Store_Name">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="# " DataField="Total">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="# Compliant " DataField="TotalCompliant">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="Compliant %" DataField="PercentageCompliance">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="Total Boxs" DataField="Boxs">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="Compliant Boxs" DataField="BoxsCompliant">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="% Compliant Boxs" DataField="PercentageBoxsCompliant">
                                                </telerik:GridBoundColumn>
                                            </Columns>
                                        </telerik:GridTableView>
                                    </DetailTables>
                                </telerik:GridTableView>
                            </DetailTables>
                        </telerik:GridTableView>
                    </DetailTables>
                    <NoRecordsTemplate>
                        <div>
                            There are no records to display</div>
                    </NoRecordsTemplate>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Division_Code" ItemStyle-Width="30px" AllowSorting="true"
                            SortExpression="Division_Code" AllowFiltering="false" UniqueName="DivisionCode"
                            HeaderText="Division">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Store_Name" AllowSorting="true" AllowFiltering="false"
                            UniqueName="StoreName" SortExpression="Store_Name" HeaderText="Store Name">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Total" AllowSorting="true" AllowFiltering="false"
                            UniqueName="Total" HeaderText="# of " SortExpression="Total"
                            ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TotalCompliant" AllowSorting="true"
                            AllowFiltering="false" UniqueName="Compliant" HeaderText="# of Compliant "
                            SortExpression="Compliant" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PercentageCompliance" AllowSorting="true"
                            AllowFiltering="false" UniqueName="CompliancePercent" HeaderText="% of  Compliance"
                            SortExpression="CompliancePercent" ItemStyle-HorizontalAlign="Right"
                            ItemStyle-Width="100px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Boxs" AllowSorting="true" AllowFiltering="false"
                            UniqueName="Boxs" HeaderText="# of Boxs (Post+Pre)" SortExpression="Boxs"
                            ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="BoxsCompliant" AllowSorting="true" AllowFiltering="false"
                            UniqueName="BoxsCompliant" HeaderText="# of Compliant Boxs" SortExpression="BoxsCompliant"
                            ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PercentageBoxsCompliant" AllowSorting="true"
                            AllowFiltering="false" UniqueName="BoxsCompliantPercent" HeaderText="% Compliant Boxs"
                            SortExpression="BoxsCompliantPercent" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>

in the code b ehind, i am binding a list to the grid

 

    gridComplianceSummary.DataSource = lstCSDivisions;
                gridComplianceSummary.MasterTableView.VirtualItemCount = 0;
                // zones
                foreach (GridTableView detailView in gridComplianceSummary.MasterTableView.DetailTables)
                {
                    detailView.Rebind();
                    detailView.VirtualItemCount = lstCSZones.Count;
                }

0
Eyup
Telerik team
answered on 11 Apr 2016, 11:44 AM
Hi Sumathi,

You can use the ServerBind or Client load mode to achieve this requirement:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/hierarchical-grid-types-and-load-modes/hierarchy-load-modes

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Jeff Wickersham
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Sumathi
Top achievements
Rank 1
Share this question
or