Exporting Gridview data in excel

Bageshkumarbagi
Posted by Bageshkumarbagi under C# category on | Points: 40 | Views : 868
Take one gridview

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

protected void Button1_Click(object sender, EventArgs e)
{
string s = System.DateTime.Now.ToShortDateString().ToString();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename="+"ON"+" " +s+ ".xls");
Response.Charset = "";
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)
{

}

Comments or Responses

Login to post response