Export an ASP.NET datagrid to HTML

Export with datagrid Render Control[-][--][++]

<codebox vbscript><%'Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter'Dim htmlWriter As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWriter)'Must turn off sorting and paging'Must also disable any custom buttons or links or image buttons in the datagrid, but I don't have any heregrdResults.AllowSorting = FalsegrdResults.AllowPaging = False'Refresh the datagrid if it's not already'The full bind here just gets the data from the database and calls the grid.Databind()Me.dvResults = NothingMe.FullBind(Session("trkDsResults"))'Render to HTMLgrdResults.RenderControl(htmlWriter)'Turn your stuff back on (and buttons, links... if any)grdResults.AllowSorting = TruegrdResults.AllowPaging = True'Now stringWriter.ToString is your HTML datagrid output'Write to a file here, if you wantDim sWriter As System.IO.StreamWritersWriter = System.IO.File.CreateText(System.Configuration.ConfigurationSettings.AppSettings("FilePathABS").Trim & "Tracker/Temp/test.xls")sWriter.Write(stringWriter.ToString)sWriter.Close()%></codebox>Then you could stream the file to their browser with ASP.NET Stream File