【发布时间】:2016-11-11 20:03:21
【问题描述】:
我有以下代码:
这是我的按钮:<asp:Button ID="Button1" runat="server" Text="Export" />
protected void Button1_Click(object sender, EventArgs e)
{
string attachment = string.Empty;
attachment = "attachment; filename=ReportName" + ".xls"; //Setting the attachment name.
HttpContext.Current.Response.ClearContent();//clears all content output from the buffer stream.
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType ="application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
htw.WriteLine("<center><b><u><font size='5'> " + attachment + " </font></u></b></center>");//will be displayed in excel as a heading.
GridView1.Parent.Controls.Add(frm);
frm.Controls.Add(GridView1);
frm.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
但是当我点击按钮时,只有页面被刷新,没有其他反应,请帮助我
我无法使用此方法:
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control)
}
【问题讨论】:
标签: c# asp.net excel gridview sharepoint