Exporting to Excel Show and Hide column in row

2 posts, 0 answers
  1. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 23 Feb 2012 Link to this post

    I have a RadGrid that shows or hides data in a certain row based on some logic in my RadGrid1_ItemDataBound method. 

    I am trying to show the column and only certain rows on the export.

    RadGrid
    First Name   MVP
    Fred             Yes
    John             No
    Bill
    Stan             Yes
    Jack             Yes

    Export to Excel
    First Name   MVP
    Fred             Yes
    John             No
    Bill                Yes
    Stan             Yes
    Jack             Yes

    As you can see I can hide "Yes" in the codebehind of the RadGrid1_ItemDataBind method, but it appears in the Export.

    How can I get "Yes" to NOT appear in the export to excel?

    protected void ButtonExcel_Click(object sender, System.EventArgs e)
       {
          ConfigureExport();
          RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");
          Grid1.MasterTableView.GetColumn("mvp").Display = true;
          // Logic here to hide certain data in the based on the MVP value
          Grid1.MasterTableView.ExportToExcel();
       }


  2. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 27 Feb 2012 Link to this post

    Michael:

    Take a look at the Rad Grid Export to Excel issue forum thread. You should be able to modify the code provided by Shinu that uses the RadGrid_ExportCellFormatting event to conditionally hide column values in the export.

    Hope this helps!

  3. DevCraft Release
Back to Top