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;
}