Hi There, I have a gridvidew (GV2). I want the user to be able to export the contents of this gridview to an excel spreadsheet for offline processing.
Here is my subroutine:
Protected Sub ExcelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExcelButton.Click
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim stringWriter As New System.IO.StringWriter()
Dim htmlWriter As New System.Web.UI.HtmlTextWriter(stringWriter)
GV2.RenderControl(htmlWriter)
Response.Write(stringWriter.ToString())
Response.End()
End Sub
On clicking the ExcelButton I get the error message:
Control 'GV2' of type 'GridView' must be placed inside a form tag with runat=server.
The control GV2 is in fact inside:
<form id="form1" runat="server"></form>