我有以下代码:
这是我的按钮:<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)
}
答案 0 :(得分:0)
public class Customer
{
public string FirstName { get; set; }
public string Gender { get; set; }
}
public partial class DetailsViewExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
BindDetails();
}
private void BindDetails()
{
DetailsView1.DataSource = new List<Customer> { new Customer { FirstName = "Customer 1", Gender = "Male" } };
DetailsView1.DataBind();
}
protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
DetailsView1.ChangeMode(DetailsViewMode.Edit);
BindDetails();
}
}