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

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
 
J

John Saunders

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?
 
K

Kathy Burke

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top