This is a migrated thread and some comments may be shown as answers.
how to export radgrid
7 Answers 86 Views
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 02 Dec 2010, 02:23 PM
i want to export radgrid in excel with column names when column autogenerated property is false and columns are dynamically generated.

i had use this code

RadGrid1.MasterTableView.ExportToExcel(); 

but it export without header text.

i want to export with header text.

7 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 02 Dec 2010, 02:55 PM
Hello Goldy,

The headers won't be exported properly if your RadGrid is invisible. Can you please confirm whether this is the case? If this is not so, please post some more information about your scenario.

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart 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
Jack
Top achievements
Rank 1
answered on 03 Dec 2010, 05:52 AM
my radgrid is visible at run time but when i export, it is exporting successfully but the headers are not coming while all the data is coming..

I am attaching a jpeg file plz see that..


   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }


   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
   foreach (DataColumn co in DT.Columns)
                {
                    GridBoundColumn bb;
                    bb = new GridBoundColumn();
                    bb.HeaderText = DT.Columns[j].Caption;
                  
                    bb.DataField = DT.Columns[j].Caption;
                    if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                    {
                        bb.Visible = false;
                    }
                    
                    j++;
                    RadGrid1.MasterTableView.Columns.Add(bb);
                    this.PlaceHolder1.Controls.Add(RadGrid1);
                    

                }
0
Daniel
Telerik team
answered on 07 Dec 2010, 10:55 PM
Hello Goldy,

Could you please post your code in this thread? I will try to create a runnable project in order to reproduce the problem on my end.
Thank you.

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart 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
Gaurav
Top achievements
Rank 1
answered on 12 Apr 2011, 07:47 AM
I am facing the same issue, column headers are not getting exported.
In my case, am making div containing the grid 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.

0
Daniel
Telerik team
answered on 14 Apr 2011, 09:25 PM
Hello Gaurav,

Below you can find a simple code-snippet that demonstrates how to export invisible RadGrid. Please try this approach and let me know whether it is suitable for you.
<asp:Button ID="Button1" runat="server" Text="Export" onclick="Button1_Click" />
<telerik:RadGrid ID="ExportGrid" runat="server" Visible="false">
    <ExportSettings ExportOnlyData="true" IgnorePaging="false" OpenInNewWindow="true" />
</telerik:RadGrid>

protected void Button1_Click(object sender, EventArgs e)
{
    ExportGrid.Visible = true;
    ExportGrid.DataSource = new string[] { "John", "Michael", "Tina" };
    ExportGrid.DataBind();
    ExportGrid.MasterTableView.ExportToExcel();
}

Note that even though I set Visible to true, the control won't be displayed on the page.

Best 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
BO
Top achievements
Rank 1
answered on 19 Jul 2015, 08:55 PM
I had the same problem (dynamically created bound columns missing header text on export).  After some tinkering, I found that rebinding the grid just before the export refreshes the grid header definition.
0
Daniel
Telerik team
answered on 21 Jul 2015, 12:49 PM
Hello Bo,

RadGrid needs to recreate its structure in such scenario and this is why you need to call Rebind (or DataBind for simple datasource scenario).
In most cases this happens when you need to show something that has been invisible before - be it columns or the whole control.

Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Jack
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jack
Top achievements
Rank 1
Gaurav
Top achievements
Rank 1
BO
Top achievements
Rank 1
Share this question
or