将gridview导出为单词

时间:2011-07-08 09:48:33

标签: asp.net gridview ms-word

     protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
            "attachment;filename=GridViewExport.doc");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-word ";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.AllowPaging = false;
            GridView1.RenderControl(hw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            /* Verifies that the control is rendered */
        }  

这是我在.cs文件中的代码我要做的是将gridview导出到word文件 但是当我运行代码时它会出错

只能在Render(); 期间调用RegisterForEventValidation  请帮忙

2 个答案:

答案 0 :(得分:1)

您可以查看this。也许this可以帮到你。

答案 1 :(得分:0)

从评论中复制答案:

得到答案的人EnableEventValidation ="false"只需要在页面指令

中添加它