开发者

Export To excel in Asp.Net

开发者 https://www.devze.com 2023-01-30 06:02 出处:网络
I havebutton on my pagefor\" Export To Excel\". The ButtonClick function isto export the datgrid (dgrISGrid) to excel Code is attached below:

I have button on my page for" Export To Excel". The ButtonClick function is to export the datgrid (dgrISGrid) to excel Code is attached below: But while executing its throwing error as"thread is aborted".Whats the solution?

    protected void imgbtnExport_Click(object sender, ImageClickEventArgs e)
    {
      try
      {

  开发者_如何转开发      Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=InformationSystems.xls");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        dgrISGrid.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
      }
      catch (Exception ex)
      {

        ExceptionHandler ObjExceptionHandler = new ExceptionHandler();
        lblError.Text = ObjExceptionHandler.GetExceptionDetails(ex);
      }
    }


Response.End() causes this error.

Try using "Response.Flush()" just before this statement.

0

精彩评论

暂无评论...
验证码 换一张
取 消