P
polabear
I'm trying to use the below code to export a gridview to excel, btu I get the
following error:
RegisterForEventValidation can only be called during Render();
Any ideas are appreciated.
Export code after the grid has been databound:
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Disposition",
"filename=C:\ExcelTestFile.xls")
Response.Charset = ""
Dim stringWriter As StringWriter = New StringWriter
Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter)
Me.grdModels.RenderControl(htmlWriter)
Response.Write(stringWriter.ToString())
Response.ContentType = "application/vnd.ms-excel"
Response.End()
Since I got an error :
Control 'ctl00_ContentPlaceHolder1_grdModels' of type 'GridView' must be
placed inside a form tag with runat=server.
I added this code:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
polarbear
following error:
RegisterForEventValidation can only be called during Render();
Any ideas are appreciated.
Export code after the grid has been databound:
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Disposition",
"filename=C:\ExcelTestFile.xls")
Response.Charset = ""
Dim stringWriter As StringWriter = New StringWriter
Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter)
Me.grdModels.RenderControl(htmlWriter)
Response.Write(stringWriter.ToString())
Response.ContentType = "application/vnd.ms-excel"
Response.End()
Since I got an error :
Control 'ctl00_ContentPlaceHolder1_grdModels' of type 'GridView' must be
placed inside a form tag with runat=server.
I added this code:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
polarbear