读书人

asp.net导出excel数据表时页面封锁

发布时间: 2013-04-26 16:27:53 作者: rapoo

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 Excel
------解决方案--------------------


asp.net导出excel数据表时页面封锁
[解决办法]
你可以在导出按钮上不这么写。
直接重定向。到另外一个页面去导出。当然如果你这导出的有搜索条件的话记得保存查询条件。
在另外个页面要解析查询条件保证2边的数据是一样的。再进行导出操作。
[解决办法]

读书人网 >asp.net

热点推荐