C
CDonlan
Here is how im exporting
I have a bound field thats of type string. It can be a combination of
letters and number. When ever that string is 1-1 ,2-3, 3-4, etc.. It
converts that to a date , like 1-Jan. Is there a way to prevent this?
Thanks.
Code:
//Clear response content and headers
response.Clear();
response.ClearContent();
response.ClearHeaders();
//Add header
response.AddHeader("content-disposition",
"attachment;filename=" + fileName + ".xls");
response.Charset = string.Empty;
response.Cache.SetCacheability(HttpCacheability.Public);
response.ContentType = "application/vnd.ms-excel";
//Create StringWriter
StringWriter stringWrite = new StringWriter();
//Create HtmlTextWriter
HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
//Remove controls from Column Headers
if (grdView.HeaderRow != null && grdView.HeaderRow.Cells !
= null)
{
for (int ct = 0; ct < grdView.HeaderRow.Cells.Count; ct
++)
{
//Save header text if found
string headerText =
grdView.HeaderRow.Cells[ct].Text;
//Check for controls in header
if (grdView.HeaderRow.Cells[ct].HasControls())
{
//Check for link buttons (used in sorting)
if
(grdView.HeaderRow.Cells[ct].Controls[0].GetType().ToString() ==
"System.Web.UI.WebControls.DataControlLinkButton")
{
//Link button found, get text
headerText =
((LinkButton)grdView.HeaderRow.Cells[ct].Controls[0]).Text;
}
//Remove controls from header
grdView.HeaderRow.Cells[ct].Controls.Clear();
}
//Reassign header text
grdView.HeaderRow.Cells[ct].Text = headerText;
}
}
//Remove unwanted columns (header text listed in
removeColumnList arraylist)
if (excludedColumnList != null)
{
foreach (DataControlField field in grdView.Columns)
{
if (excludedColumnList.Contains(field.HeaderText))
{
field.Visible = false;
}
}
}
//Call GridView's RenderControl method
grdView.RenderControl(htmlWrite);
//Add style to ensure that numeric data treated as text
will retain the leading zeros.
string style = @"<style> .zeroLeftPad { mso-number-format:
\@; } </style> ";
response.Write(style);
//Write Response to browser
response.Write(stringWrite.ToString());
response.End();
I have a bound field thats of type string. It can be a combination of
letters and number. When ever that string is 1-1 ,2-3, 3-4, etc.. It
converts that to a date , like 1-Jan. Is there a way to prevent this?
Thanks.