private void ExportToExcel(string
strFileName, GridView dg)
{
DataTable
dt = GetData();
dg.AllowPaging = false;
dg.DataSource = dt;
dg.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/excel";
System.IO.StringWriter
sw = new System.IO.StringWriter();
HtmlTextWriter
htw = new HtmlTextWriter(sw);
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
No comments:
Post a Comment