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

RadGrid Export

8 Answers 528 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CarlosCisneros
Top achievements
Rank 1
CarlosCisneros asked on 03 Sep 2008, 11:32 PM
Hi.
I have a doubt, i need to export from a radgrid to an excel file, i'm using 

RadGrid4.ExportSettings.ExportOnlyData =

False

RadGrid4.ExportSettings.IgnorePaging =

True

RadGrid4.ExportSettings.OpenInNewWindow =

True

RadGrid4.MasterTableView.ExportToExcel()

and it works just fine, but i would like to know if there is a way to export columns that are hidden, because i'm only showing 4 columns and there are like 50 columns on the table and i need to export all of them but i'm just getting the ones that are not hidden, is there a way get them all?

thanks in advanced.

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Sep 2008, 03:56 AM
Hi Carlos,

Try the following code snippet to export all the columns in the Grid.

CS:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        RadGrid1.ExportSettings.OpenInNewWindow = true
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            col.Visible = true
        } 
        RadGrid1.Rebind(); 
        RadGrid1.MasterTableView.ExportToWord(); 
 
    } 


Regards
Princy.
0
CarlosCisneros
Top achievements
Rank 1
answered on 04 Sep 2008, 11:44 PM

thanks princy that solved my problem, but now i have the same issue with a detail table, i need to show all visible and invisible fields on master table and detail tables, as well i need to expand all master table items.

my code behind so far is like this.

RadGrid1.ExportSettings.ExportOnlyData = true;

RadGrid1.ExportSettings.IgnorePaging = false;

RadGrid1.ExportSettings.OpenInNewWindow = true;

foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)

{

col.Visible = true;

}

RadGrid1.Rebind();

foreach (GridItem gi in RadGrid1.Items)

{

gi.Expanded = true;

}

RadGrid1.MasterTableView.ExportToExcel();


but i can only make visible master table columns, also when i set ignorepaging true crashes with following error.

Specified argument was out of the range of valid values.
Parameter name: value

do you have any idea why is that.

thanks in advanced.

0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Sep 2008, 04:24 AM
Hi Carlos,

You can try the following code snippet to export both Master and Detail table.

CS:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        RadGrid1.ExportSettings.OpenInNewWindow = true
        RadGrid1.ExportSettings.IgnorePaging = true
        RadGrid1.ExportSettings.ExportOnlyData = true
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            col.Visible = true
        } 
        foreach (GridColumn ChildCol in RadGrid1.MasterTableView.DetailTables[0].RenderColumns) 
        { 
            ChildCol.Visible = true
        } 
        
        RadGrid1.MasterTableView.ExportToWord();  
    } 

Regards
Princy.
0
e
Top achievements
Rank 2
answered on 08 Apr 2010, 09:21 PM
I tried hiding columns by setting the Visible property to false. I set it in the ItemDataBound event, but it doesn't seem to work with the ExcelML format. Is there a reason for that?
0
Daniel
Telerik team
answered on 14 Apr 2010, 11:54 AM
Hello,

You shouldn't have any problems to hide the desired columns on ItemDataBound however it would be better if you hide them on button click or ItemCommand (depending on your scenario).

I attached a runnable demo to this thread. Let me know if you need further assistance.

Kind regards,
Daniel
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Sumit
Top achievements
Rank 1
answered on 25 Sep 2012, 10:43 AM
I am using templates for certain columns and those columns are hidden. I am using following code in the Event Handler of Button Export As CSV :



foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
        {
            col.Visible = true;
        }
RadGrid1.MasterTableView.ExportToCSV();

Still downloaded csv file is not showing hidden columns.

Any suggestions?

0
Kostadin
Telerik team
answered on 28 Sep 2012, 10:56 AM
Hi Sumit,

On my side everithing works as expected. Make sure you set the Text property on the GridDataItems before exporting.

I prepared a small sample and attached it to this forum post. I hope this helps.

Regards,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Sumit
Top achievements
Rank 1
answered on 28 Sep 2012, 11:00 AM
Hi Kostadin,
                  Thanks for your reply
I was using LiteralControl inside my template. I replaced it with Label, now export function works like a charm.
RadGrid strips all Literals by default.
Tags
Grid
Asked by
CarlosCisneros
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
CarlosCisneros
Top achievements
Rank 1
e
Top achievements
Rank 2
Daniel
Telerik team
Sumit
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or