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.
精彩评论