exporting gridview to 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-wor开发者_StackOverflowd ";
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 */
}
this is my code in the .cs file what am trying to do is export a gridview to word file but when i run the code it gives an error
RegisterForEventValidation can only be called during Render(); pls help
Copying the answer from comment:
got the answer guys EnableEventValidation ="false"
just have to add this in the page directive
精彩评论