Exporting a Server Control into Microsoft Excel
public void DownLoad(string strFileName)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
Panel1.RenderControl(htw); // here u can use gridview, panel etc.....
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
public override void VerifyRenderingInServerForm(Control control) // u must put this method on the code behind page.
{
}
No comments:
Post a Comment