Private Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
'LoopHierarchyRecursive(grdEmpData.MasterTableView)
grdEmpData.MasterTableView.HierarchyDefaultExpanded =
True
'grdEmpData.MasterTableView.Rebind()
grdEmpData.ExportSettings.ExportOnlyData =
True
'grdEmpData.ExportSettings.IgnorePaging = True
grdEmpData.MasterTableView.AllowPaging =
False
grdEmpData.ExportSettings.OpenInNewWindow =
True
grdEmpData.ExportSettings.FileName =
"SAPDataList"
grdEmpData.MasterTableView.ExportToExcel()
End Sub
Sub LoopHierarchyRecursive(ByVal gridTableView As GridTableView)
For Each nestedViewItem As GridNestedViewItem In gridTableView.GetItems(GridItemType.NestedView)
nestedViewItem.Expanded = True
If nestedViewItem.NestedTableViews.Length > 0 Then
'now you can access: nestedViewItem.NestedTableViews[0].Items, which will be the DataItems of this nested table
'then make recursive call
LoopHierarchyRecursive(nestedViewItem.NestedTableViews(0))
' above [0] stands for the first table in the hierarchy, since Telerik RadGrid supports multiple tables at a level
End If
Next
End Sub
Here is the structure and code:
MainGrid
MaterTableView
DetailTable
NestedViewTemplate (using nested view because each detail table row will have different datasource)
ChildGrid
<MasterTableView Name="EmployeeList" GridLines="None" DataKeyNames="SAPEmployeeNo" AllowSorting="True" ShowHeader="True">
<DetailTables>
<telerik:GridTableView DataKeyNames="EmployeeNo, CategoryId" Name="Category" Width="1050px" runat="server" PagerStyle-Position="bottom">
<NestedViewTemplate>
<telerik:RadGrid ID="EmpData" OnNeedDataSource="gridEmpData_NeedDataSource" runat="server" Width="1050px">
<ItemStyle CssClass="RadGridItem"></ItemStyle>
<AlternatingItemStyle CssClass="RadGridItem"></AlternatingItemStyle>
<ClientSettings>
<Scrolling AllowScroll="true" ScrollHeight="40px" UseStaticHeaders="true" />
</ClientSettings>
</telerik:RadGrid>
</NestedViewTemplate>
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="EmployeeNo" MasterKeyField="EmployeeNo" />
</ParentTableRelation>
<Columns>
<telerik:GridBoundColumn DataField="EmployeeNo" UniqueName="EmployeeNo" Visible="false" />
<telerik:GridBoundColumn DataField="CategoryId" UniqueName="CategoryId" Visible="false" />
<telerik:GridBoundColumn HeaderText="" DataField="CategoryName" SortExpression="CategoryName" UniqueName="CategoryName" />
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridTemplateColumn UniqueName="btnEdit" HeaderStyle-Width="30px" ItemStyle-Width="30px">
<ItemTemplate>
<asp:ImageButton ImageAlign=AbsBottom id="btnEditEmp" runat="server" imageurl="~/images/edit.gif" alternatetext="Edit" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn HeaderText="EmpNo" DataField="EmployeeNo" SortExpression="EmployeeNo" UniqueName="EmployeeNo" />
<telerik:GridBoundColumn HeaderText="Last Name" DataField="LastName" SortExpression="LastName" UniqueName="LastName" />
<telerik:GridBoundColumn HeaderText="First Name" DataField="FirstName" SortExpression="FirstName" UniqueName="FirstName" />
<ExpandCollapseColumn ButtonType="ImageButton" Visible="False" UniqueName="ExpandColumn"></ExpandCollapseColumn>
</MasterTableView>
Thanks!
11 Answers, 1 is accepted
Try setting the IgnorePaging property in the ExportSettings of the Grid to true along with the HierarchyDefaultExpanded property and see whether the details tables are also getting exported along with the master table.
VB:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) |
RadGrid2.ExportSettings.ExportOnlyData = True |
RadGrid2.MasterTableView.HierarchyDefaultExpanded = True |
RadGrid2.ExportSettings.IgnorePaging = True |
RadGrid2.ExportSettings.OpenInNewWindow = True |
RadGrid2.MasterTableView.ExportToExcel() |
End Sub |
Shinu
MaterTableView
DetailTable (1st level table)
NestedViewTemplate (using nested view because each detail table row above will have different datasource)
ChildGrid (2nd level table)
Please examine the code snippet bellow and let me know if it works for you.
VB.NET:
Protected Sub Button1_Click(sender As Object, e As EventArgs) |
ConfigureExport() |
RadGrid1.MasterTableView.HierarchyDefaultExpanded = True |
RadGrid1.Rebind() |
RadGrid1.MasterTableView.ExportToExcel() |
End Sub |
Public Sub ConfigureExport() |
RadGrid1.ExportSettings.ExportOnlyData = True |
RadGrid1.ExportSettings.IgnorePaging = True |
RadGrid1.ExportSettings.OpenInNewWindow = True |
End Sub |
I hope this helps.
Kind regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
To avoid duplicate posts, we can continue our communication on the subject in the support ticket that you have opened on the matter.
Kind regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Here is the code I am using to produce this:
case "Export to Excel (Hierarchical)":
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.IgnorePaging = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
RadGrid1.MasterTableView.ExportToExcel();
break;
Any help on how to export this third level with hierarchy intact is much appreciated.
Thanks
Kris
Attached to this message is a simple working project which handles the desired functionality. Please give it a try and let me know if it works for you.
I hope this helps.
Best wishes,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Hiii,
I am facing problem in exporting nested template in to pdf. Every time ,it gives me a default pdf export ( without the data in nested template). For the same structure, I am able to export nested view in excel suucssfully.
I am surprised with this behaviour as line of codes for both export are lmost name
here is the code snippet, I am using
For export to Excel: ( This works fine and export nested Data also)
RadGrid1.ExportSettings.ExportOnlyData =true;
RadGrid1.ExportSettings.IgnorePaging =
true;
RadGrid1.ExportSettings.OpenInNewWindow =
true;
RadGrid1.ExportSettings.HideStructureColumns =
true;
RadGrid1.MasterTableView.HierarchyDefaultExpanded =
true;
RadGrid1.Rebind();
RadGrid1.MasterTableView.ExportToExcel();
For export to PDF:( this only gives up default Data)
RadGrid1.ExportSettings.ExportOnlyData =
true;
RadGrid1.ExportSettings.Pdf.PageWidth =
Unit.Pixel(900);
RadGrid1.ExportSettings.Pdf.PageHeight =
Unit.Pixel(612);
RadGrid1.ExportSettings.IgnorePaging =
true;
RadGrid1.ExportSettings.OpenInNewWindow =
true;
RadGrid1.ExportSettings.Pdf.PageTitle = TitleDoc;
RadGrid1.MasterTableView.HierarchyDefaultExpanded =
true;
RadGrid1.Rebind();
RadGrid1.MasterTableView.ExportToPdf();
One thing, I noticed there is nochange in behviour even if I remove
RadGrid1.Rebind() line.
In nested template we are using a list view and binding its columns.
<
NestedViewTemplate>
<asp:Panel ID="panel1" runat="server" BorderStyle="Solid" BorderWidth="2px">
<telerik:RadListView ID="RadListView1" runat="server" DataSourceID="ObjectDataSource1"
ItemPlaceholderID="ParentContainer">
<LayoutTemplate>
<fieldset>
<legend>Terminal Details</legend>
<asp:PlaceHolder ID="ParentContainer" runat="server" />
</fieldset>
</LayoutTemplate>
<ItemTemplate>
<table id="Table1" style="width: 750px; height: 40px" runat="server">
<tr>
<td style="width: 75%">
<table id="Table2" style="width: 700px; height: 20px" runat="server">
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<asp:Label ID="Label1" runat="server" Text="SITE ID:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label2" runat="server" Text="SITE NAME:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label3" runat="server" Text="ADDRESS:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label4" runat="server" Text="CITY:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label5" runat="server" Text="STATE:" Font-Bold="true"></asp:Label>
</td>
</tr>
<%
-- This row is for values of a label --%>
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<%
# Eval("SITE_ID")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("SITE_NAME")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("ADDRESS")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("CITY")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("STATE")%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 75%">
<table id="Table3" style="width: 700px; height: 20px" runat="server">
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<asp:Label ID="Label6" runat="server" Text="PARENT ID:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label7" runat="server" Text="SERIAL 1:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label8" runat="server" Text="SERIAL 2:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label9" runat="server" Text="LUNO:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label10" runat="server" Text="MODE NAME" Font-Bold="true"></asp:Label>
</td>
</tr>
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<%
# Eval("PARENT_ID")%>
</td>
<td style="width: 140px;" align="left">
<%
#Eval("SERIAL1")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("SERIAL2")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("LUNO")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("MODE_NAME")%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 75%">
<table id="Table4" style="width: 700px; height: 40px" runat="server">
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<asp:Label ID="Label12" runat="server" Text="MODEL NAME:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label13" runat="server" Text="MANUFACTURER NAME:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label14" runat="server" Text="TYPE NAME:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label15" runat="server" Text="PHONE1:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label11" runat="server" Text="PHONE2:" Font-Bold="true"></asp:Label>
</td>
</tr>
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<%
# Eval("MODEL_NAME")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("MANUFACTURER_NAME")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("TYPE_NAME")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("PHONE1")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("PHONE2")%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 75%">
<table id="Table5" style="width: 700px; height: 40px" runat="server">
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<asp:Label ID="Label16" runat="server" Text="PHONE3:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label17" runat="server" Text="PHONE4:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label18" runat="server" Text="COMM DATE 1:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label19" runat="server" Text="COMM DATE 2:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label20" runat="server" Text="TRANS DATE LAST:" Font-Bold="true"></asp:Label>
</td>
</tr>
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<%
# Eval("PHONE3")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("PHONE4")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("COMM_DATE_1")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("COMM_DATE_2")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("TRANS_DATE_LAST")%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 75%">
<table id="Table6" style="width: 700px; height: 40px" runat="server">
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<asp:Label ID="Label21" runat="server" Text="SURCHARGE:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label23" runat="server" Text="BIN EXEMPT:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label24" runat="server" Text="xyz1:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label25" runat="server" Text="xyz2:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label22" runat="server" Text="xyz3:" Font-Bold="true"></asp:Label>
</td>
</tr>
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<%
# Eval("SURCHARGE")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("BIN_EXEMPT")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("xyz1")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("xyz2")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("xyz3")%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 75%">
<table id="Table7" style="width: 700px; height: 40px" runat="server">
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<asp:Label ID="Label26" runat="server" Text="AID ACCESS CUST:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label27" runat="server" Text="AID CONTRACT FL:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label28" runat="server" Text="AID CONTRACT SL:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label29" runat="server" Text="AID CONTRACT CASH:" Font-Bold="true"></asp:Label>
</td>
<td style="width: 140px;" align="left">
<asp:Label ID="Label30" runat="server" Text="PARENT NAME:" Font-Bold="true"></asp:Label>
</td>
</tr>
<tr style="width: 100%; height: 20px">
<td style="width: 140px;" align="left">
<%
# Eval("AID_ACCESS_CUST")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("AID_CONTRACT_FL")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("AID_CONTRACT_SL")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("AID_CONTRACT_CASH")%>
</td>
<td style="width: 140px;" align="left">
<%
# Eval("PARENT_NAME")%>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadListView>
</asp:Panel>
</NestedViewTemplate>
please suggest me ..what different settings are required for PDF...
I tried setting up an export the way you were instructed to and it worked on my side. You can find a sample project attached demonstrating this approach working for a RadGrid with a RadListView in its NestedViewTemplate.
Additionally, you can check if the issue persists when you remove from the RadListView control's ItemTemplate and LayoutTemplate - all tags which are not server controls?
I hope this helps.
Best wishes,
Pavlina
the Telerik team
To see the example on how to export all expanded detail Grids you can refer to this Visual Studio project below:
https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/detail-grid-excel-export
Another project that shows how to export all pages and all expanded detail Grids is available here:
https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/detail-grid-excel-export-all-pages-all-details
I hope this helps.
Regards,
Pavlina
Telerik