Code to export html table (.RenderControl) doesn't like sort headings?

  • Thread starter Thread starter Kathy Burke
  • Start date Start date
K

Kathy Burke

Hi again,

I have a datagrid which uses several fields such as:

<asp:BoundColumn DataField="DateEntered" HeaderText="Date Entered"
SortExpression="DateEntered"></asp:BoundColumn>

All works ok, until I put this code in the page to allow the user save
the html table as an excel file:

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition",
"attachment;filename=MyFileName.xls")
Response.Charset = ""
Me.EnableViewState = False

'get datagrid HTML from the control, write straight to browser
Dim objSW As New System.IO.StringWriter()
Dim objHTW As New System.Web.UI.HtmlTextWriter(objSW)
dg.RenderControl(objHTW)
Response.Write(objSW.ToString())
Response.End()

I get a global failure saying: System.Web.HttpException: Control
'dg__ctl1__ctl0' of type 'DataGridLinkButton' must be placed inside a
form tag with runat=server.

this control is the DateEntered sort column heading in the datagrid
(first control of the row).

Any clues, as always, greatly appreciated...this one is driving me a bit
nuts.

Thanks,

Kathy
 
Kathy Burke said:
Hi again, ....
I get a global failure saying: System.Web.HttpException: Control
'dg__ctl1__ctl0' of type 'DataGridLinkButton' must be placed inside a
form tag with runat=server.

Kathy,

Is it possible that the exception message is telling you the truth?
 
Hmmm, John, it's hard to trust what a machine tells me! :-)

Anyhow, this code worked for my co-worker but then I realized he wasn't
using sort columns in the header. I ended up binding to the datasource
in the sub and then rendering. Works ok now.

Thanks,

Kathy
 
Back
Top