public void ExportToExcel(DataTable dt)
{
if (dt.Rows.Count > 0)
{
string filename = "Sample.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Grid1.DataSource = dt;
Grid1.DataBind();
//Get HTML for the control.
Grid1.RenderControl(hw);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
}
{
if (dt.Rows.Count > 0)
{
string filename = "Sample.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Grid1.DataSource = dt;
Grid1.DataBind();
//Get HTML for the control.
Grid1.RenderControl(hw);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
}
No comments:
Post a Comment