Dario Zanelli
Top achievements
Rank 1
Dario Zanelli
asked on 12 Feb 2010, 03:57 PM
Hi all!
I need to export to an excel file the content of my RadGrid.
The exporting is working fine, but I have some hidden columns that aren't exported.
I have tried like follows to make visible those columns, but it doesn't work. If I make not visible a column that is visible instead it is working.
protected void mngBtnExcel_Click(Object sender, EventArgs e)
{
this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Visible = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Visible = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Visible = false;
this.grdRcm.ExportSettings.ExportOnlyData = true;
this.grdRcm.ExportSettings.IgnorePaging = true;
this.grdRcm.ExportSettings.OpenInNewWindow = true;
this.grdRcm.MasterTableView.ExportToExcel();
this.grdRcm.MasterTableView.GetColumn("Process").Visible = false;
this.grdRcm.MasterTableView.GetColumn("SubprocessDescr").Visible = false;
}
The columns "Process" nad "SubProcessDescr" are not visible, but I need to export them.
Thanks and best regards.
Dario
I need to export to an excel file the content of my RadGrid.
The exporting is working fine, but I have some hidden columns that aren't exported.
I have tried like follows to make visible those columns, but it doesn't work. If I make not visible a column that is visible instead it is working.
protected void mngBtnExcel_Click(Object sender, EventArgs e)
{
this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Visible = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Visible = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Visible = false;
this.grdRcm.ExportSettings.ExportOnlyData = true;
this.grdRcm.ExportSettings.IgnorePaging = true;
this.grdRcm.ExportSettings.OpenInNewWindow = true;
this.grdRcm.MasterTableView.ExportToExcel();
this.grdRcm.MasterTableView.GetColumn("Process").Visible = false;
this.grdRcm.MasterTableView.GetColumn("SubprocessDescr").Visible = false;
}
The columns "Process" nad "SubProcessDescr" are not visible, but I need to export them.
Thanks and best regards.
Dario
10 Answers, 1 is accepted
0
Schlurk
Top achievements
Rank 2
answered on 12 Feb 2010, 04:55 PM
Whenever you hide/unhide columns the best property to use would be "Display" as opposed to "Visible". The Display properly simply changes the style while the Visible can be used if you wish to not render the columns. I think if you replace all of your visible's with display this might help you.
0
Dario Zanelli
Top achievements
Rank 1
answered on 15 Feb 2010, 08:20 AM
Hi Schlurk!
Thanks for your answer. I tried but it doesn't work. Here there is my code:
protected void mngBtnExcel_Click(Object sender, EventArgs e)
{
this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Display = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Display = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Display = false;
this.grdRcm.ExportSettings.ExportOnlyData = true;
this.grdRcm.ExportSettings.IgnorePaging = true;
this.grdRcm.ExportSettings.OpenInNewWindow = true;
this.grdRcm.MasterTableView.ExportToExcel();
this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Display = false;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Display = false;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Display = true;
}
The resulting file doesn't show the columns "Process" and "SubprocessDescr" and shows the "EditCommandColumn"
Is there another way to select the columns that I need?
Best regards,
Dario Zanelli
Thanks for your answer. I tried but it doesn't work. Here there is my code:
protected void mngBtnExcel_Click(Object sender, EventArgs e)
{
this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Display = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Display = true;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Display = false;
this.grdRcm.ExportSettings.ExportOnlyData = true;
this.grdRcm.ExportSettings.IgnorePaging = true;
this.grdRcm.ExportSettings.OpenInNewWindow = true;
this.grdRcm.MasterTableView.ExportToExcel();
this.grdRcm.MasterTableView.Columns.FindByUniqueName("Process").Display = false;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("SubprocessDescr").Display = false;
this.grdRcm.MasterTableView.Columns.FindByUniqueName("EditCommandColumn").Display = true;
}
The resulting file doesn't show the columns "Process" and "SubprocessDescr" and shows the "EditCommandColumn"
Is there another way to select the columns that I need?
Best regards,
Dario Zanelli
0
Hello Dario,
You shouldn't have to change the state of the columns after exporting since this code will affect the exported file only. Please try the following approach:
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.
You shouldn't have to change the state of the columns after exporting since this code will affect the exported file only. Please try the following approach:
protected
void
mngBtnExcel_Click(Object sender, EventArgs e)
{
this
.grdRcm.MasterTableView.GetColumn(
"Process"
).Display =
true
;
this
.grdRcm.MasterTableView.GetColumn(
"SubprocessDescr"
).Display =
true
;
this
.grdRcm.MasterTableView.GetColumn(
"EditCommandColumn"
).Display =
false
;
this
.grdRcm.ExportSettings.ExportOnlyData =
true
;
this
.grdRcm.ExportSettings.IgnorePaging =
true
;
this
.grdRcm.ExportSettings.OpenInNewWindow =
true
;
this
.grdRcm.MasterTableView.ExportToExcel();
}
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
Amy Liu
Top achievements
Rank 1
answered on 26 Aug 2011, 04:04 PM
Hello!
A simple question: I used the image in the grid. How can I put the code in the image click event?
I used GridExporting event and put the display=true code inside. It seem to me that it doesn't work.
Is it a click event also ? where?
Thanks.
Amy
A simple question: I used the image in the grid. How can I put the code in the image click event?
I used GridExporting event and put the display=true code inside. It seem to me that it doesn't work.
Is it a click event also ? where?
Thanks.
Amy
0
Hello Amy,
I suppose you mean that you export the control via the built-in image buttons. If this is so, I would recommend that you hide/show the desired columns within the ItemCommand event when e.CommandName is equal to "ExportToExcel".
Best regards,
Daniel
the Telerik team
I suppose you mean that you export the control via the built-in image buttons. If this is so, I would recommend that you hide/show the desired columns within the ItemCommand event when e.CommandName is equal to "ExportToExcel".
Best regards,
Daniel
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
0
Steele
Top achievements
Rank 1
answered on 09 Sep 2011, 02:09 AM
Hi Daniel,
I too am handling this scenario - using the default Export button in the Command item for the grid.
Following your final advice of changing the Display of the columns in the ItemCommand event, I have found that this affects the Grid when it is refreshed. Basically, the columns to be shown only in the export get shown to the grid in the page.
This is undesireable.
I have tried to change the Display property in the radgrids GridExporting event, but it seems that this is too late in the cycle, as none of the changes take affect in the resulting Excel document.
Any tips on when to re-hide the columns??
Thanks,
Steele.
I too am handling this scenario - using the default Export button in the Command item for the grid.
Following your final advice of changing the Display of the columns in the ItemCommand event, I have found that this affects the Grid when it is refreshed. Basically, the columns to be shown only in the export get shown to the grid in the page.
This is undesireable.
I have tried to change the Display property in the radgrids GridExporting event, but it seems that this is too late in the cycle, as none of the changes take affect in the resulting Excel document.
Any tips on when to re-hide the columns??
Thanks,
Steele.
0
Steele
Top achievements
Rank 1
answered on 09 Sep 2011, 05:12 AM
Just thought I'd put up my work around for this. Though it does seem a little clunky.
Now if this is left as is, the columns become visible once the grid is refreshed, so we fix this up in the prerender :
You can see that I am setting UseStaticHeaders to true here. My grid has this value set on creation, but it gets lost after the export has occurred. Is this a bug??
Hope this helps.
void
rg_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"ExportToExcel"
)
{
RadGrid rg = (RadGrid)sender;
rg.MasterTableView.GetColumn(
"CountOfRespDone"
).Display =
true
;
rg.MasterTableView.GetColumn(
"TotalOfResp"
).Display =
true
;
rg.MasterTableView.GetColumn(
"RespToDo"
).Display =
true
;
}
}
Now if this is left as is, the columns become visible once the grid is refreshed, so we fix this up in the prerender :
void
rg_PreRender(
object
sender, EventArgs e)
{
RadGrid rg = (RadGrid)sender;
rg.MasterTableView.GetColumn(
"CountOfRespDone"
).Display =
false
;
rg.MasterTableView.GetColumn(
"TotalOfResp"
).Display =
false
;
rg.MasterTableView.GetColumn(
"RespToDo"
).Display =
false
;
rg.ClientSettings.Scrolling.UseStaticHeaders =
true
;
}
You can see that I am setting UseStaticHeaders to true here. My grid has this value set on creation, but it gets lost after the export has occurred. Is this a bug??
Hope this helps.
0
Hello Steele,
I'm unable to recreate this scenario. Please download the attached demo and see what is missing. I would appreciate it, if you could modify this project to help me reproduce the problem.
Best regards,
Daniel
the Telerik team
I'm unable to recreate this scenario. Please download the attached demo and see what is missing. I would appreciate it, if you could modify this project to help me reproduce the problem.
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
Ramprit
Top achievements
Rank 2
answered on 22 Apr 2015, 10:32 AM
Export to excel in radgrid but there without using CommandItemDisplay="Top" i am not able to see export button when i use CommandItemDisplay="Top" than it show Edit on left side on the top side i have not req- that how to hide this please help me.....
0
chetna
Top achievements
Rank 1
answered on 19 Sep 2016, 06:32 AM
Thank u so much for your Answer , It works !!!