GridView must be added to a form tag for rendering
.net, asp.net, c#
Solution
Just add the following code in your page
public override void VerifyRenderingInServerForm(Control control)
{
return;
}
To learn more about it, read the MSDN documentation.
Problem
``` TextWriter tr = new StringWriter(); HtmlTextWriter writer = new HtmlTextWriter(tr); HtmlForm form = new HtmlForm(); form.Controls.Add(divQueryDescription); divQueryDescription.RenderControl(writer); <div runat="server" id="divQueryDescription"> <asp:GridView runat="server" id="grv"></asp:GridView> </div> ``` My GridView is inside a DIV and I add that DIV to an HtmlForm, so that I can render it to a string. But I get the following error:- Gridview 'grv' must be placed inside a form tag with runat=server, although my Gridview is already inside a form because I added my DIV to the form. How can I render this DIV to a string ?