M
Mike P
I am using the following code to export my gridview to excel :
protected void btnExport_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving
than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the
specified ASP.NET server control at run time.
}
My problem is that I am setting the text values of one of the columns in
the RowDataBound event, and doing so seems to mean that the text for
this column is not exported, whereas if I don't set the text in the
RowDataBound event, the text is exported.
Here is my code for RowDataBound:
switch (Probability.Text)
{
case "0.25":
e.Row.Cells[4].Text = "A (25%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.PowderBlue;
break;
case "0.5":
e.Row.Cells[4].Text = "B (50%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.DeepSkyBlue;
break;
Can anybody help with this?
protected void btnExport_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving
than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the
specified ASP.NET server control at run time.
}
My problem is that I am setting the text values of one of the columns in
the RowDataBound event, and doing so seems to mean that the text for
this column is not exported, whereas if I don't set the text in the
RowDataBound event, the text is exported.
Here is my code for RowDataBound:
switch (Probability.Text)
{
case "0.25":
e.Row.Cells[4].Text = "A (25%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.PowderBlue;
break;
case "0.5":
e.Row.Cells[4].Text = "B (50%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.DeepSkyBlue;
break;
Can anybody help with this?