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

Export to Excel check box issue

4 Answers 390 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Goran
Top achievements
Rank 1
Goran asked on 08 Feb 2013, 11:45 AM
Hi,

We use Telerik grid for VS2008, version 2011.3.1115.0.

I have 2 issues:

1) When I create columns manually in this way:

<div style="margin-right: 20px;">
    <telerik:RadGrid ID="RadGrid1" runat="server" Width="100%" DataSourceID="SqlDataSource1" AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
        AutoGenerateColumns="false" AllowMultiRowSelection="true">
        <MasterTableView PageSize="10" AllowPaging="True" Width="100%" DataKeyNames="ContinentID" DataSourceID="SqlDataSource1" EditMode="InPlace">
            <Columns>
                <telerik:GridClientSelectColumn></telerik:GridClientSelectColumn>
                <telerik:GridBoundColumn HeaderText="ContinentID" DataField="ContinentID"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="ContinentName" DataField="ContinentName"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
            <Selecting AllowRowSelect="true"></Selecting>
        </ClientSettings>
    </telerik:RadGrid>
</div>

The code behind is as follows:

RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.IgnorePaging = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToExcel();

When I export grid to Excel file the Boolean values from first check box column are exported as well. How can I export all data but without those Boolean values?

2) When I want to export data only from selected rows from grid that contains the first check box column to Excel file using the following code:

foreach (GridDataItem item in RadGrid1.Items)
{
    if (item.Selected == false)
    {
        item.Visible = false;
    }
}
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.IgnorePaging = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToExcel();

not only selected rows, but whole grid was exported.

How can I solve these 2 issues?

Thank you in advance.

Goran

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Feb 2013, 12:47 PM
Hi,

Try hiding the ClientSelectColumn before exporting. With reference to this forum thread, You have to set IgnorePaging="false" in order to export the selected rows in this case. Otherwise you should persist the selected items manually and then use the ItemCreated event to hide the items that are not selected.
Note that IgnorePaging=true"  will cause RadGrid to rebind since it have to get all items from the datasource.


C#:
protected void Button1_Click(object sender, EventArgs e)
{
        RadGrid1.MasterTableView.GetColumn("Uniquename").Visible = false;//hide the clientselectcolumn
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.MasterTableView.ExportToExcel();
}

Thanks,
Princy
0
Goran
Top achievements
Rank 1
answered on 11 Feb 2013, 05:25 AM
It works. Thanks a lot Princy.
0
P
Top achievements
Rank 1
answered on 29 Feb 2016, 05:56 PM

How is it possible to hide the checkbox value if IgnorePaging="true"?

 

I've tried to hide the column :

RadGrid1.MasterTableView.Columns(0).Visible = False

And I've tried to hide the control :

For Each item As GridDataItem In RadGrid1.Items
Dim cb As CheckBox = DirectCast(item.FindControl("cb"), CheckBox)
cb.Visible = False
Next

Neither work when IgnorePaging="true"

 

Thanks
           

0
P
Top achievements
Rank 1
answered on 29 Feb 2016, 07:21 PM

I was able to figure this out.  In case anyone is wondering... I used the Display property rather than visible and it works

So.. 

RadGrid1.Columns(0).Display = False

rather than

RadGrid1.Columns(0).Visible = False

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