Hi
I have below code & i want TextBox first column not to be exported. After export file also attached

C#
protected void LinkButtonExport_Click(object sender, EventArgs e)
{
try
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "SessionsBookPlanning.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grdPlanning.AllowPaging = false;
GetData();
grdPlanning.HeaderRow.Style.Add("background-color", "#FFFFFF");
for (int i = 0; i < grdPlanning.HeaderRow.Cells.Count; i++)
{
grdPlanning.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
}
grdPlanning.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
catch (Exception ex)
{
Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLoginCode.Value));
ShowMessage("Oops...", ex.Message, "error");
}
}Thanks

Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 20, 2023, 3:44 AM EDT
protected void LinkButtonExport_Click(object sender, EventArgs e) { try { Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "SessionsBookPlanning.xls")); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grdPlanning.AllowPaging = false; GetData(); grdPlanning.HeaderRow.Style.Add("background-color", "#FFFFFF"); for (int i = 0; i < grdPlanning.HeaderRow.Cells.Count; i++) { grdPlanning.HeaderRow.Cells[i].Style.Add("background-color", "#df5015"); } // Exclude the first column from export grdPlanning.Columns[0].Visible = false; grdPlanning.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); // Set the first column back to visible for future rendering grdPlanning.Columns[0].Visible = true; } catch (Exception ex) { Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLoginCode.Value)); ShowMessage("Oops...", ex.Message, "error"); } }In this modified code, we use the
Visibleproperty of the first column (grdPlanning.Columns[0].Visible) to hide it during the export process. After exporting, we set theVisibleproperty back to true so that the column will be visible again during future rendering of the GridView.