如题:
在一个框架,左侧是功能链接,右侧对应的是相应的页面,现在在右侧点击'导出'按钮,保存完EXCEL文件后,再点击左侧的其它功能链接,则没反应,打不开.也没提示.
DataGrid导出EXCEL的代码如下:
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(DataGrid1);
this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
在一个框架,左侧是功能链接,右侧对应的是相应的页面,现在在右侧点击'导出'按钮,保存完EXCEL文件后,再点击左侧的其它功能链接,则没反应,打不开.也没提示.
DataGrid导出EXCEL的代码如下:
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(DataGrid1);
this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
解决方案 »
- js或者jquery怎么刷新当前页面
- 年前棘手问题,求解决,求安心过年
- MVC3中CodeFirst数据库初始化数据添加失败
- 急待解决:给已有图片添加:文字+logo图片的水印效果
- 问个登陆的问题
- 复合表头的repeater导出excel的问题
- 学习ASPNET?
- socket的问题:您的主机中的软件放弃了一个已建立的连接
- 在c#代码中怎么用javascript语句(window.open())打开一个窗口,使打开的窗口固定大小没有菜单栏工具栏,并且指定在一个框架中打开(tar
- 怎么知道弹出的对话框是否关闭了?
- 当客户端非正常退出,如何快速清理其Session?
- IP显示问题,如何使IP的最后一位为*?
if (!IsPostBack)
{
string sql="select code,dwf_name from dwfinanceins where jc=2"; //金融机构
DropDownList1.DataSource=mydata.dbbind(sql);
DropDownList1.DataTextField="dwf_name";
DropDownList1.DataValueField="code";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0,new System.Web.UI.WebControls.ListItem("请选择单位","请选择单位"));
}
左边点击URL后,有边打开A,
A页面输入日期和部门后,点击导出按钮Response.Redirect到b页面,b页面根据A传递过来的日期部门参数导出到EXCELL.每次导出成功后,左边的该连接也不能用了,IE提示有错误.我这里应该不是Response.End()的原因吧.最后改成JS的open()可以导出了,以前的问题也没有了.但会打开一个空的窗口b.而且有可能被客户屏蔽的,那样就导不出了.
-----------
private void Button1_Click(object sender, System.EventArgs e)
{
Page.RegisterClientScriptBlock("output","<script>window.open( 'TraceOutToExcel.aspx?start_time="+startTime.Value.ToString()+"&end_time="+endTime.Value.ToString()+"')</script>");
}
我用下面的方法解决的
http://community.csdn.net/Expert/topic/4339/4339412.xml?temp=.8470728