将gridview导出到excel,该更新位于gridview外部的按钮单击事件的更新面板中
问题描述:
我有1个页面,我想在Excel工作表中导出gridview的内容,并且gridview在更新面板中.我希望在按钮的click事件上,Gridview的内容应该在excel中导出
I have 1 page on that i want to export the contents of gridview in the excel sheet and gridview is in the update panel.i want that on the click event of button the gridview''s contents should be export in the excel sheet.and the button is outside the gridview.
答
在函数中尝试此代码
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment; filename = g.xls");
Response.Charset =";
Response.ContentType ="application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter ht =新的HtmlTextWriter(sw);
gvDisplay.AllowPaging = false;
gvDisplay.DataBind();
gvDisplay.RenderControl(ht);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
在aspx.cs页面中,只需编写以下方法
公共重写void VerifyRenderingInServerForm(Control control)
{
}
祝你好运
快乐编码
Hi,
Try this code in function
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=g.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter ht = new HtmlTextWriter(sw);
gvDisplay.AllowPaging = false;
gvDisplay.DataBind();
gvDisplay.RenderControl(ht);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
and in aspx.cs page Just write following method
public override void VerifyRenderingInServerForm(Control control)
{
}
Good Luck
happy coding