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

Discussion in 'ASP .Net' started by Kathy Burke, Nov 10, 2003.

  1. Kathy Burke

    Kathy Burke Guest

    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!
     
    Kathy Burke, Nov 10, 2003
    #1
    1. Advertising

  2. "Kathy Burke" <> wrote in message
    news:...
    > 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?
    --
    John
     
    John Saunders, Nov 11, 2003
    #2
    1. Advertising

  3. Kathy Burke

    Kathy Burke Guest

    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!
     
    Kathy Burke, Nov 11, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    2
    Views:
    418
    Andreas Klemt
    Jul 24, 2003
  2. Ken Boone via .NET 247

    form RenderControl doesn't work in win app

    Ken Boone via .NET 247, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    816
    Norman Yuan
    Sep 22, 2004
  3. sajuptpm
    Replies:
    7
    Views:
    832
    Terry Reedy
    Sep 8, 2010
  4. Martin Perfelian

    Using RenderControl to get HTML from a System.Web.UI.UserControl

    Martin Perfelian, Oct 9, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    317
    John Saunders
    Oct 9, 2003
  5. Navin
    Replies:
    1
    Views:
    765
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page