Details View Data export in Excel Sheet
Hi,
I have 3 DetailsView Data Controls on my .aspx page.
These 3 Controls Display data from 3 different tables from a Access Database.
I want to Export the Data of these 3 Data Controls in an Excel sheet.
SO I used the following code :-
Private Sub ExportToExcel(ByVal strFileName As String, ByVal dg As DetailsView)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim oStringWriter As New System.IO.StringWriter
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
DetailsView1.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.[End]()
End Sub
Protected Sub ExcelButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExcelButton1.Click
ExportToExcel("Report.xls", GridView1)
End Sub
But its showing me Error :-
Control 'DetailsView1' of type 'DetailsView' must be placed inside a form tag with runat=server.
Line 18: DetailsView1.RenderControl(oHtmlTextWriter)
But the <form> tag with runat="server" is already there.
How to solve this & if there is some other code to export the data to Excel.
Thank You......!!
-Anup
|