Export GridData to Excel
Export data from Datagrid to Excel
private void btnExportToExcel_Click(object sender,System.EventArgs e)
{
ExportToExcel("Report.xls",DataGrid1);
}
private void ExportToExcel(string strFileName,DataGrid dg)
{
Response.Clear();
Response.Buffer = true;Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition","attachment;filename=" + strFileName);
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new StringWriter();
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw);
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Happy Programming
0 Comments:
Post a Comment
<< Home