This is doing my nut in. I've got a simple function that i've used countless times in VS 2003 .net 1.1 projects to export a dataset to Excel.
When i use this function in Visual Web Developer .net 2.0 projects though it exports the whole HTML page to excel, not just the supplied dataset.
The function is:
And is called from the page like: ConvertToExcel(YourDatasetName, Response)
tied to a buttons onclick event (plus code to generate dataset 'YourDatasetName').
Anyone know why this doesnt just export the dataset (it'll also export any text or images on the page that contains the button) or does anyone have a decent alternative .net 2.0 VB example as simple as this one?
Ta.
When i use this function in Visual Web Developer .net 2.0 projects though it exports the whole HTML page to excel, not just the supplied dataset.
The function is:
Code:
Sub ConvertToExcel(ByVal ds As DataSet, ByVal response As HttpResponse)
response.Clear()
response.Charset = ""
'set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
'create a string writer
Dim stringWrite As New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
'instantiate a datagrid
Dim dg As New DataGrid
'set the datagrid datasource to the dataset passed in
dg.DataSource = ds.Tables(0)
'bind the datagrid
dg.DataBind()
'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'all that's left is to output the html
response.Write(stringWrite.ToString)
HttpContext.Current.ApplicationInstance.CompleteRequest()
End Sub
tied to a buttons onclick event (plus code to generate dataset 'YourDatasetName').
Anyone know why this doesnt just export the dataset (it'll also export any text or images on the page that contains the button) or does anyone have a decent alternative .net 2.0 VB example as simple as this one?
Ta.

Nah, still the same. Cant understand it, it just ignores the data sent to the function and writes the entire page to Excel.
Comment