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

[Solved] Export auto generated checkbox column

2 Answers 278 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jan
Top achievements
Rank 1
Jan asked on 27 May 2009, 01:25 PM
Hello,

I want to do an Excel export of a grid with AutoGenerated columns. The problem is that for a GridCheckboxColumn in Excel the cell is empty, I want it to have true/false, 0/1, etc.

In another thread it's advised to create a hidden column and show that before export, but I am afraid i can't use that because it is impossible to add a column between two autogenerated columns? We really need the auto-generated columns...

Any help would be much appreciated.

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 May 2009, 07:22 AM
Hello Jan,

The possible approach to your scenario is to replace the CheckBoxColumn with a BoundColumn and toggle the visibility while exporting. You can also swap the columns on exporting so that the  boundcolumn appears at the position of the checkboxcolumn while exporting. Check out the code below to understand better:
aspx:
 <telerik:RadGrid ID="RadGrid1" AllowPaging="true" PageSize="6"DataSourceID="SqlDataSource1" AutoGenerateColumns="true" runat="server"
       <MasterTableView>        
        <Columns> 
        <telerik:GridBoundColumn UniqueName="ConditionDuplicate" DataField="Condition" HeaderText="Condition" Visible="false"</telerik:GridBoundColumn> 
            ..... 

c#:
protected void btnExport_Click(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.SwapColumns("Condition","ConditionDuplicate"); 
        RadGrid1.MasterTableView.GetColumn("Condition").Visible = false
        RadGrid1.MasterTableView.GetColumn("ConditionDuplicate").Visible = true
        RadGrid1.ExportSettings.ExportOnlyData = true
        RadGrid1.ExportSettings.OpenInNewWindow = true
        RadGrid1.ExportSettings.IgnorePaging = true
        RadGrid1.MasterTableView.ExportToExcel(); 
    } 

Thanks
Princy


0
Jan
Top achievements
Rank 1
answered on 28 May 2009, 08:34 AM
Thanks a lot Princy, SwapColumns works wonderfully :)

Jan
Tags
Grid
Asked by
Jan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jan
Top achievements
Rank 1
Share this question
or