I have a web page with a populated datagrid on it, that has sort functions
on several of the columns.
I have a routine that runs immediately before the code below that clears the
controls.
The code below is then supposed to execute:
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
DataGrid1.RenderControl(hw)
Response.AppendHeader("content-disposition", "attachment; filename=" & sFile
& ".xls")
' Remove the charset from the Content-Type header.
'Response.Charset = ""
' Turn off the view state.
'Me.EnableViewState = False
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
What I get is a zero byte file that I am prompted to either open or save.
Either action will result in an "Unable to read file" message.
I've tweaked the other commands (response.charset, and viewstate) on or off,
and it hasn't made any difference. This is giving me the same error message
when I just have a response.contenttype command in the stream without doing
the rendercontrol. I can't read that file either. I've shuffled these
commands around too, having the rendercontrol immediately before the
response.write command.
Does anyone have any idea what's going on with this code? Or do you have an
example of some code that DOES work?
I am lost on this.
SC