日期:2014-05-17  浏览次数:20549 次

asp.net导出excel数据表时页面关闭!
下面的方法倒是能导出数据,但页面就关闭了!我不想页面关闭怎么改?
public void ExcelOut(GridView gv)
      {//导出Excel表的方法   
          if (gv.Rows.Count > 0)
          {//有数据行   
              Response.Clear();
              Response.ClearContent();
              Response.AddHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");//以系统时间设置为文件名   
              Response.ContentEncoding = System.Text.Encoding.UTF8;//UTF8编码   
              Response.ContentType = "application/ms-excel";//文件类型   
              StringWriter sw = new StringWriter();
              HtmlTextWriter htw = new HtmlTextWriter(sw);
              gv.RenderControl(htw);
              Response.Write(sw.ToString());
              Response.Flush();
              Response.End();//结束   
          }
          else
          {
              Response.Write("<script>alert('没有数据!');location='AuditDetail.aspx?parentId="+parentId+"&id="+id+"'</script>");
          }
      }
     
      public override void VerifyRenderingInServerForm(Control control)   
      { } 
   //导出excel按钮
    protected void BtnExport_Click(object sender, EventArgs e)
        {
            DataTable dt = selfManager.Sel_AuditDetailed(id);
            GridView GV = new GridView();
            GV.DataSource = dt.DefaultView;       
            GV.AllowPaging = false;
            GV.DataBind();
            ExcelOut(GV);//调用方法   
           
        }
 
ASP.NET