H
hedgracer
I have a gridview that has six columns. I need to hide the last column
(i.e. not download it) in the download from gridview to excel. My
current code (which downloads the entire gridview) is as follows:
public static void ExportExcelFile(Control htmlData, string
filename)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename="
+ filename + ".xls");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/
vnd.xls";
System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
htmlData.RenderControl(htmlWrite);
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}
I am calling this by the following code:
protected void btnDownloadDebit_Click(object sender, EventArgs e)
{
grvDebit.Columns[5].Visible = false;
Util.ExportExcelFile(grvDebit, "DebitDetail");
grvDebit.Columns[5].Visible = true;
}
I thought that making the fifth column's visible property to false
before the call would result in that column not being downloaded. I
was wrong. Can anyone give me some advice on this? Thanks for all help
in advance.
Dave
(i.e. not download it) in the download from gridview to excel. My
current code (which downloads the entire gridview) is as follows:
public static void ExportExcelFile(Control htmlData, string
filename)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename="
+ filename + ".xls");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/
vnd.xls";
System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
htmlData.RenderControl(htmlWrite);
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}
I am calling this by the following code:
protected void btnDownloadDebit_Click(object sender, EventArgs e)
{
grvDebit.Columns[5].Visible = false;
Util.ExportExcelFile(grvDebit, "DebitDetail");
grvDebit.Columns[5].Visible = true;
}
I thought that making the fifth column's visible property to false
before the call would result in that column not being downloaded. I
was wrong. Can anyone give me some advice on this? Thanks for all help
in advance.
Dave