Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
When I export the Gridview to Excel, I get an error like this. Can you help me?
My code example is as follows.
Dim SqlQuery As String = "SELECT * FROM vBasketbollTournamet ORDER BY 1 ASC"
Dim cmd1 As New SqlCommand(SqlQuery, conn)
Dim adp1 As New SqlDataAdapter(cmd1)
adp1.Fill(dt2)
GridView1.DataSource = dt2
GridView1.DataBind()
Dim oStringWriter As New StringWriter()
Dim oHtmlTextWriter As New HtmlTextWriter(oStringWriter)
GridView1.GridLines = GridLines.Horizontal
GridView1.HeaderStyle.Font.Bold = True
GridView1.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.[End]()
I think, you can use below the example.
.aspx file contens
.aspx.vb file contents