Hi,
I am working on hierarchical grid where I am having 3 details tables each one resides inside other. It is like drilldown feature. My next task is to export complete data on the grid to Excel and PDF. The view under excel should be similar to that on html page.
I am getting that, but there are few problems...
1. For each detail table it is showing me header which I dont want to show. It is working fine for html page but not working for Excel, PDF.
2. I am having total 12 columns of which 3 are having Name, address, origin all are linkbuttons. It is showing me all text as as link in excel which I dont want to show.
3. I dont want to show ExpandCollapse button inside Excel, which is showing presently
Please suggest how to overcome these problems.
Thanks,
Pradip
5 Answers, 1 is accepted
Thanks,
Pradip
Try the following code snippet in the Click event of the Export button to hide the headers for the child table.
CS:
protected void Button1_Click(object sender, EventArgs e) |
{ |
RadGrid1.MasterTableView.HierarchyDefaultExpanded = true; |
RadGrid1.MasterTableView.Rebind(); |
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) |
{ |
if (item.Expanded) |
{ |
foreach (GridTableView childTable in item.ChildItem.NestedTableViews) |
{ |
foreach (GridHeaderItem header in childTable.GetItems(GridItemType.Header)) |
{ |
header.Visible = false; |
} |
} |
} |
} |
RadGrid1.ExportSettings.ExportOnlyData = true; |
RadGrid1.ExportSettings.OpenInNewWindow = true; |
RadGrid1.MasterTableView.ExportToExcel(); |
} |
Go through the following help article which explains how to export GridButtonColumn data. Go through the section entitled
'Exporting GridButtonColumn/GridTemplateColumn/GridHyperLinkColumn data' in the article.
Exporting tips and tricks
You may also refer the application done by telerik in the following forum link and see how the Expand/Collapse column is being hidden in the exported document.
Hiding ExpandColumn on Export
Thanks
Shinu
Hi Shinu,
Thanks for the reply!
My grid look like as follows, it is not complete just for your reference....
It is having 2 LinkButtons, when i am exporting this to Excel it is also showing me link. Could you please guide me how to remove these links so that we wont get it in Excel-PDF?
<
Columns >
<telerik:GridNumericColumn DataField="division_id" DataType="System.Int64" HeaderText="Division ID" UniqueName="DivisionDivisionID" Visible="false">
</telerik:GridNumericColumn>
<telerik:GridTemplateColumn HeaderText="<%$ Resources:Generic, Division %>" UniqueName="DivisionDivision" DataField="division_name" >
<ItemTemplate>
<asp:LinkButton id="lnkDivisionName" Font-Bold="true" ForeColor="Navy" text='<%# Container.DataItem("division_name")%>' CommandName="ExpandCollapse" runat="server" ToolTip="Click to expand/collapse the Site information for this Division" >
</asp:LinkButton>
</ItemTemplate>
<HeaderStyle Width="147px" />
</telerik:GridTemplateColumn>
<telerik:GridNumericColumn DataField="division_id" DataType="System.Int64" HeaderText="Division ID" UniqueName="DivSiteDivisionID" Visible="false">
</telerik:GridNumericColumn>
<telerik:GridTemplateColumn HeaderText="<%$ Resources:Generic, Site %>" UniqueName="DivisionSite">
<ItemTemplate>
<asp:LinkButton id="lnkDivisionSiteName" ForeColor="Navy" text='<%# Container.DataItem("site_name")%>' CommandName="ExpandCollapse" runat="server" ToolTip="Click to expand/collapse the Account information for this Site">
</asp:LinkButton>
</ItemTemplate>
<HeaderStyle Width="149px" />
</telerik:GridTemplateColumn>..................
.............
Thanks,
Pradip
Have you set ExportOnlyData to true in the Click event of the Export button? If not try setting it to true and see whether the linkbuttons are getting removed.
CS:
RadGrid1.ExportSettings.ExportOnlyData = true; |
RadGrid1.MasterTableView.ExportToExcel(); |
Shinu
Thanks,
Pradip