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

Export radgrid to Excel, not exporting the column headers.

5 Answers 681 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gaurav
Top achievements
Rank 1
Gaurav asked on 12 Apr 2011, 07:50 AM
i want to export radgrid in excel with column names (Header Texts). Am using below code to achieve this :-

RadGrid1.MasterTableView.ExportToExcel(); 

but it exports the data without header text,whereas i want to export the data with header text.

I am making div containing the grid as invisible at run time, which is my requirement.

Is there any way to export column headers too along with the data ??

Note :- I cannot show the grid on the page as it is specially created for the purpose of export.

Any kind of help will be highly appreciated

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Apr 2011, 08:54 AM
Hello Gaurav,

I have found this forum discussed similar scenario.
Header is not exporting during export to excel

Thanks,
Shinu.
0
Gaurav
Top achievements
Rank 1
answered on 12 Apr 2011, 10:17 AM
Thanks for the reply shinu, but it din't help me.
I want to modify my post, the columns are not generated dynamically in my case.
The grid is being bound to a data source and i have specified the data field properties for the columns in aspx page.

Any idea why Column headers are not getting exported.
0
Daniel
Telerik team
answered on 14 Apr 2011, 09:47 PM
Hello Gaurav,

Please try the code-snippet posted in this thread:
Link to public post

Kind regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start 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
sanoj
Top achievements
Rank 1
answered on 04 Jul 2014, 09:42 AM
hi,
Even i am facing the same issue.
if the radgrid being exported to excel is invisible, the excel is losing the column headers.

Thanks,
Sanoj
0
Princy
Top achievements
Rank 2
answered on 04 Jul 2014, 11:02 AM
Hi Sanoj,

The headers won't be exported properly if your RadGrid is invisible. You can set the radgrid visibility to True on the Export button click, this will not display the control on the page. Please take a look at the sample code snippet.

ASPX:
<asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
<asp:Button ID="btnHide" runat="server" Text="Hide" OnClick="btnHide_Click" />
<telerik:RadGrid ID="rgrdExport" runat="server" AutoGenerateColumns="false" DataSourceID="dsGridDetails" AllowPaging="true>
    <MasterTableView >
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />        
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void btnExport_Click(object sender, EventArgs e)
{
    rgrdExport.Visible = true;
    rgrdExport.ExportSettings.IgnorePaging = true;
    rgrdExport.ExportSettings.ExportOnlyData = true;
    rgrdExport.MasterTableView.ExportToExcel();
}
protected void btnHide_Click(object sender, EventArgs e)
{
    rgrdExport.Visible = false;
}

Thanks,
Princy
COGIT
Top achievements
Rank 1
commented on 11 Jun 2021, 06:58 PM

This solution fixed my problem, thanks Princy! Without adding the control to a placeholder, the control is still invisible.
Tags
General Discussions
Asked by
Gaurav
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gaurav
Top achievements
Rank 1
Daniel
Telerik team
sanoj
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or