Response.Write("Export to excel");
Response.Clear();
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=Demo.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter stringwriter = new StringWriter();
HtmlTextWriter htmwrite = new HtmlTextWriter(stringwriter);
GridView1.RenderControl(htmwrite);
Response.Write(stringwriter.ToString());
Response.End();
This is my code to export gridview to excel. but an error is shown as
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Pls help me to correct this