
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

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.

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.

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.

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.

foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
{
col.Visible = true;
}
RadGrid1.MasterTableView.ExportToCSV();
Still downloaded csv file is not showing hidden columns.
Any suggestions?
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

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.