Hi There,
public void import_Click(object sender, EventArgs e)
{
Myliteral.Text = "";
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=DataTable.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn("NAME");
DataColumn dc2 = new DataColumn("ADDRESS");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
DataRow dr1 = dt.NewRow();
GridView GRid1 = new GridView();
this.GRid1.Rows.Add("1", yourtext);
this.GRid1.Rows.Add("2", yourtext2);
GRid1. DataSource() = dt;
GRid1.BindData();
for (int i = 0; i < GRid1.Rows.Count; i++)
{
GRid1.Rows[i].Attributes.Add("class", "textmode");
}
GRid1.RenderControl(hw);
string style = @"<style> .textmode { mso-number-format:\@; } style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
return;
}</style>
i hope this will work for you .