Home All Groups Group Topic Archive Search About

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

Author
25 Aug 2006 2:41 PM
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
--
=============
VB .NET Developer
http://www.rocketscience.uk.com