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

hide column in radgrid but unhide when exporting to excel

2 Answers 119 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vitaly
Top achievements
Rank 1
Vitaly asked on 31 Jul 2014, 04:32 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 01 Aug 2014, 03:20 AM
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.
0
Vitaly
Top achievements
Rank 1
answered on 01 Aug 2014, 01:10 PM
Thank you very much..it works.
Tags
General Discussions
Asked by
Vitaly
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Vitaly
Top achievements
Rank 1
Share this question
or