100分求助!急~~~~在线等。。

syb1045 syb1045 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在用户控件中放入有UpdatePanel. 里面有GridView , 现在我想把它的数据导入到Excel文档。

public void ExportResult(DataSet ds)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
for (int i = 0; i < ds.Tables.Count; i++)
{
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[i];
dg.DataBind();
dg.RenderControl(htmlWrite);
}
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=text.xls");

HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}

protected void Button2_Click(object sender, EventArgs e)
{

ExportResult(ds);

}
调用该方法后,提示好像是说Response.Write()那里出错了。到网上找信息。 说要重写
public override void VerifyRenderingInServerForm(Control control){}
可是我重写这个方法却提示找不到合适的方法来重写, 继续上网查 说改EnableEventValidation = "false".
改了 但是还是没效果。。。
请问我改如何才能解决这个问题。 。 帮帮忙。。。谢谢了。。
有点乱,不知道说清楚没。

...全文
评论 20
收藏 已收藏
分享
返回顶部
syb1045
.NET社区 62,271 成员 668,968 内容