hide column in radgrid but unhide when exporting to excel

3 posts, 0 answers
  1. Vitaly
    Vitaly  avatar
    68 posts
    Member since:
    Aug 2011

    Posted 31 Jul 2014 Link to this post

    Good morning,
    I have a Radgrid in my aspx.page with some columns:

    <telerik:RadGrid ID="EmplReqGrid" runat="server" Skin="Office2010Blue"
    GridLines="None" AllowPaging="true" AllowSorting="true"
    onexcelmlexportrowcreated="EmplReqGrid_ExcelMLExportRowCreated"
    onexcelmlexportstylescreated="EmplReqGrid_ExcelMLExportStylesCreated"
    onitemcommand="EmplReqGrid_ItemCommand" onitemcreated="EmplReqGrid_ItemCreated"
    onitemdatabound="EmplReqGrid_ItemDataBound"
    onneeddatasource="EmplReqGrid_NeedDataSource"
    onpageindexchanged="EmplReqGrid_PageIndexChanged"
    onpagesizechanged="EmplReqGrid_PageSizeChanged"
    onpdfexporting="EmplReqGrid_PdfExporting"
    onsortcommand="EmplReqGrid_SortCommand" >
    <ExportSettings FileName="EmplReqRpt" OpenInNewWindow="true" IgnorePaging="true" ExportOnlyData="true">
    <Excel Format="ExcelML" FileExtension="xls"/>
    <Pdf FontType="Subset" PaperSize="letter" />
    </ExportSettings>
    <MasterTableView AutoGenerateColumns="false" AllowMultiColumnSorting="true" >
    <CommandItemSettings />
    <Columns>

    <telerik:GridBoundColumn HeaderText="Eis-Id" DataField="PRI" UniqueName="PRI" ReadOnly="True" SortExpression="PRI" HeaderButtonType="TextButton" >
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn HeaderText="NAME" DataField="NAME" UniqueName="NAME" Visible="false" >
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn HeaderText="ReqNo" DataField="TRKNO" UniqueName="TRKNO" ReadOnly="True" SortExpression="TRKNO" HeaderButtonType="TextButton" >
    </telerik:GridBoundColumn>

    I would like to hide column name "NAME" from radgrid when displaying on the screen and unhide when I click on export to excel button:

    protected void ExporttoExcel_Click1(object sender, ImageClickEventArgs e)
    {
    try
    {
    if (!IsPostBack)
    return;

    RadGrid ReqInfoGrid = (RadGrid)EmpReqReport.FindItemByValue("EmployeeData").FindControl("EmplReqGrid");
    ReqInfoGrid.DataSource = Session["dtGrid"];
    ReqInfoGrid.DataBind();
    ReqInfoGrid.MasterTableView.ExportToExcel();

    Please help.
    Thanks so much.


    }
    catch (Exception ex)
    {
    throw;
    }
    }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Jul 2014 in reply to Vitaly Link to this post

    Hi Vitaly,

    Try to set the Display property of "Name" column to False in aspx and on button click make it display to True as follows.

    ASPX:
    ...
    <
    telerik:GridBoundColumn HeaderText="NAME" DataField="NAME" UniqueName="NAME"
        Display="false">
    </telerik:GridBoundColumn>
    ...

    C#:
    protected void rbtnExporttoExcel_Click(object sender, EventArgs e)
    {
         ....
        EmplReqGrid.MasterTableView.GetColumn("NAME").Display = true;
        EmplReqGrid.MasterTableView.ExportToExcel();
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vitaly
    Vitaly  avatar
    68 posts
    Member since:
    Aug 2011

    Posted 01 Aug 2014 Link to this post

    Thank you very much..it works.
Back to Top