Felipe Delgado
Top achievements
Rank 1
Felipe Delgado
asked on 17 Oct 2009, 12:31 AM
Hi!
I am using an export button within the toolbar of my radgrid, and it's work very good, but now I need to hide some columns and show others before export the content of the radgrid to excel. Can somebody tell me how to do it?
Thanks so much.
I am using an export button within the toolbar of my radgrid, and it's work very good, but now I need to hide some columns and show others before export the content of the radgrid to excel. Can somebody tell me how to do it?
Thanks so much.
7 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 19 Oct 2009, 05:18 AM
Hi,
You can try out the following code to hide columns in the grid before exporting:
c#:
Thanks
Princy.
You can try out the following code to hide columns in the grid before exporting:
c#:
| protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
| { |
| if (e.CommandName == RadGrid.ExportToExcelCommandName) |
| { |
| RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible = false; |
| } |
| } |
Thanks
Princy.
0
Felipe Delgado
Top achievements
Rank 1
answered on 19 Oct 2009, 02:45 PM
Thanks a lot Princy, it's really work!
Do you know if I can use the GridExporting Event instead of Item Command?
Thank you again.
Do you know if I can use the GridExporting Event instead of Item Command?
Thank you again.
0
Karan
Top achievements
Rank 1
answered on 05 Feb 2013, 01:26 AM
This hides the column in the export alright, but after the export the columns are also hidden in the browser view.
Is there a way to only hide the columns for excel export but keep them visible in the browser ?
Thanks
Is there a way to only hide the columns for excel export but keep them visible in the browser ?
Thanks
0
Princy
Top achievements
Rank 2
answered on 05 Feb 2013, 05:42 AM
Hi,
Unfortunately I cannot replicate the issue at my end. Here is the full code that I tried which worked as expected.
aspx:
C#:
Please elaborate your scenario if it doesn't help.
Thanks,
Princy
Unfortunately I cannot replicate the issue at my end. Here is the full code that I tried which worked as expected.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="false" OnItemCommand="RadGrid1_ItemCommand"> <MasterTableView CommandItemDisplay="Top"> <CommandItemSettings ShowExportToExcelButton="true" /> <Columns> <telerik:GridBoundColumn DataField="ShippedDate" UniqueName="ShippedDate"></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID"></telerik:GridBoundColumn> </Columns> </MasterTableView></telerik:RadGrid>protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e){ if (e.CommandName == RadGrid.ExportToExcelCommandName) { RadGrid1.MasterTableView.GetColumn("OrderID").Visible = false; } }Please elaborate your scenario if it doesn't help.
Thanks,
Princy
0
Karan
Top achievements
Rank 1
answered on 06 Feb 2013, 01:00 AM
Thanks for the reply Princy, The problem was with our cache that was storing the columns. We were reusing the columns hence setting the visible = false means that next time when we use that column it would not render in the browser. We have fixed this problem.
We are still having a problem with the Template column. Is there a way to change the temple column cell data in the exported excel file.
For eg. I have a template column with an Image and a hyperlink next to it. But when I export this to excel I just want to see the hyperlink and not the image. At the moment the default export just generates a blank cell. If possible please post an example.
Thanks for your help.
We are still having a problem with the Template column. Is there a way to change the temple column cell data in the exported excel file.
For eg. I have a template column with an Image and a hyperlink next to it. But when I export this to excel I just want to see the hyperlink and not the image. At the moment the default export just generates a blank cell. If possible please post an example.
Thanks for your help.
0
Princy
Top achievements
Rank 2
answered on 06 Feb 2013, 05:56 AM
Hi,
Try the following code to achieve your scenario.
C#:
Thanks,
Princy
Try the following code to achieve your scenario.
C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == RadGrid.ExportToExcelCommandName) { foreach (GridDataItem item in RadGrid1.Items) { Image img = (Image)item.FindControl("Image1"); img.Visible = false; HyperLink link = (HyperLink)item.FindControl("HyperLink1"); link.Visible = true; } }}Thanks,
Princy
0
Paul
Top achievements
Rank 1
answered on 19 Oct 2015, 10:24 PM
Princy:
You Rock!
- Paul