private void Button3_Click(object sender, System.EventArgs e)
{
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dtgPCA.HeaderStyle.Font.Bold = true;
dtgPCA.DataBind();
dtgPCA.RenderControl(hw);
Response.AddHeader("content-disposition", "attachment;filename=d:\\documents\\PCAADetails.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
=========================================================
Hope it helps.
-Manas
=======================================
If this post is useful to you, please mark it as answer.