将gridview导出到excel,该更新位于gridview外部的按钮单击事件的更新面板中 [英] export gridview to excel that is in the update panel on the click event of button that is outside the gridview

查看:71
本文介绍了将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


这篇关于将gridview导出到excel,该更新位于gridview外部的按钮单击事件的更新面板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆