100分求助!急~~~~在线等。。
我在用户控件中放入有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".
改了 但是还是没效果。。。
请问我改如何才能解决这个问题。 。 帮帮忙。。。谢谢了。。
有点乱,不知道说清楚没。
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".
改了 但是还是没效果。。。
请问我改如何才能解决这个问题。 。 帮帮忙。。。谢谢了。。
有点乱,不知道说清楚没。
...全文
相关推荐
南开19春学期(1709、1803、1809、1903)《概率论与数理统计》在线作业(100分)
南开19春学期(1709、1803、1809、1903)《概率论与数理统计》在线作业(100分)
行政决策学在线作业100分.doc
行政决策学在线作业100分.doc
华师在线基础教育改革100分作业.doc
华师在线基础教育改革100分作业.doc
川农《创新思维学本科》在线作业100分答案.pdf
川农《创新思维学本科》在线作业100分答案.pdf
计算机基础(在线作业)100分.docx
本资源是一份计算机基础在线作业,总分为100分,包含16道题目,涵盖了计算机基础知识的多个方面。以下是主要内容的详细解析:1. **计算机分类** - 根据计算机处理数据的方式(数字、模拟或混合)


