开发者

Export To excel in Asp.Net

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜