Error using GridView's RenderControl property during Export to Excel
When you try to Export the results from a GridView to excel using the GridView's RenderControl property, one might face an error stating that the server control must be placed inside a form tag with runat="server".
We can overcome this problem by ovverriding the Page.VerifyRenderingInServerForm() Method. This confirms that for a specified ASP.NET server control an HtmlForm control is rendered at run time.
Following is a sample piece of code:
protected void btnExport_Click(object sender, EventArgs e)
{
System.IO.StringWriter objStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter);
GridView1.RenderControl(objHtmlTextWriter);
Response.Write(objStringWriter.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
Check whether u have written