public void ExportToExcel(string strFileName, DataGrid dataGrid)
{
Response.ClearContent();
string attachment = String.Concat(“attachment; filename=”, strFileName ,”.xls”);
Response.AddHeader(“content-disposition”, attachment);
Response.ContentType = “application/ms-excel”;
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
dataGrid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Advertisement