Export to Excel check box issue

5 posts, 1 answers
  1. Goran
    Goran avatar
    51 posts
    Member since:
    Jun 2012

    Posted 08 Feb 2013 Link to this post

    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
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Feb 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Goran
    Goran avatar
    51 posts
    Member since:
    Jun 2012

    Posted 10 Feb 2013 Link to this post

    It works. Thanks a lot Princy.
  5. P
    P avatar
    4 posts
    Member since:
    Mar 2012

    Posted 29 Feb Link to this post

    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
               

  6. P
    P avatar
    4 posts
    Member since:
    Mar 2012

    Posted 29 Feb in reply to P Link to this post

    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

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017