Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Kathy Burke
Guest
 
Posts: n/a
#1: Nov 17 '05
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

John Saunders
Guest
 
Posts: n/a
#2: Nov 17 '05

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


"Kathy Burke" <kathyburke40@attbi.com> wrote in message
news:OWORja9pDHA.2940@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi again,[/color]
....[color=blue]
> 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.[/color]

Kathy,

Is it possible that the exception message is telling you the truth?
--
John



Kathy Burke
Guest
 
Posts: n/a
#3: Nov 17 '05

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


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Closed Thread