protected void btnExportExcel_Click(object sender, EventArgs e)
{
DataSet ds = CurrentApproverService.GetReportData(depID, UserID);
DataGrid dg = new DataGrid();
dg.DataSource = ds;
dg.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + "ReportData.xls");
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();
dg = null;
dg.Dispose();
}
No comments:
Post a Comment