Using Gridview To Export Data To Excel Error (ASP.NET 2.0)

J

JumpingMattFlash

I'm attempting to use the following code to render a datatable as excel
format. However in a perfectly valid page i get the error: Control
'ctl00_ContentPlaceHolder1_GridView1' of type 'GridView' must be placed
inside a form tag with runat=server.

VB.NET:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

Dim cReport As New SBL.cSSReport
Dim LevelID() As Integer = {0}
Dim dt As DataTable =
cReport.Execute(SBL.ReportType.Offline.AllFields, Session("Username"),
Session("DateFrom"), Session("DateTo"), LevelID,
SnapshotBusinessLayer.Globals.gOrgLevel.Company).Tables(0)

'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=test.xls")

GridView1.DataSource = dt
GridView1.DataBind()
GridView1.RenderControl(writer)
End Sub

Any help which can be provided would be very much appreciated

Thanks, Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top