Dynamically creating <DIV> statement

Discussion in 'ASP .Net' started by Jennifer Mathews, Mar 10, 2009.

  1. ' The <table> has two rows.
    Dim oTbl As New Table
    Dim oTR1 As New TableRow
    Dim oTR2 As New TableRow
    Dim oTD1 As New TableCell
    Dim oTD2 As New TableCell

    oTD1.Text = "Whatever One" ' Row 1
    oTR1.Controls.Add(oTD1)
    oTbl.Controls.Add(oTR1)

    oTD2.Text = "Whatever Two" ' Row 2
    oTR2.Controls.Add(oTD2)
    oTbl.Controls.Add(oTR2)

    plchld_One.Controls.Add(oTbl) ' plchld_One is a PlaceHolder control on the page.
    ' This all works fine.
    ' -------------------------------

    ' just changing the code above a bit.
    Dim oPanl As New Panel
    oPanl.ID = "myPanel"
    oPanl.Visible = False

    oTD2.Text = "Whatever Two" ' Row 2
    oTR2.Controls.Add(oTD2)
    oPanl.Controls.Add(oTR2) ' Add a PANEL ( = <div id="myPanel">) generates an error on
    the next row.
    oTbl.Controls.Add(oPanl) ' <<<<<<< 'Table' cannot have children of type 'Panel'.
    ' -------------------------------

    ' So the question is:
    ' How can I dynamically generate a <div> so I can Hide a row?

    <table>
    <tr>
    <td>Whatever One</td>
    </tr>
    <div id="myPanel"> << how do I do this in CODE ?
    <tr>
    <td>Whatever Two</td>
    </tr>
    </div>
    <table>


    Thanks
    ~Jennifer~
     
    Jennifer Mathews, Mar 10, 2009
    #1
    1. Advertising

  2. Jennifer Mathews

    sloan Guest

    The error looks correct to me: You can't just throw in a <div> in the
    middle of a table.



    This would be what you're after I think:



    <table>
    <tr>
    <td>Whatever One</td>
    </tr>

    <tr><td>

    <div id="myPanel">

    </td></tr>


    <tr>
    <td>Whatever Two</td>
    </tr>
    </div>
    <table>


    "Jennifer Mathews" <> wrote in message
    news:...
    >' The <table> has two rows.
    > Dim oTbl As New Table
    > Dim oTR1 As New TableRow
    > Dim oTR2 As New TableRow
    > Dim oTD1 As New TableCell
    > Dim oTD2 As New TableCell
    >
    > oTD1.Text = "Whatever One" ' Row 1
    > oTR1.Controls.Add(oTD1)
    > oTbl.Controls.Add(oTR1)
    >
    > oTD2.Text = "Whatever Two" ' Row 2
    > oTR2.Controls.Add(oTD2)
    > oTbl.Controls.Add(oTR2)
    >
    > plchld_One.Controls.Add(oTbl) ' plchld_One is a PlaceHolder control on
    > the page.
    > ' This all works fine.
    > ' -------------------------------
    >
    > ' just changing the code above a bit.
    > Dim oPanl As New Panel
    > oPanl.ID = "myPanel"
    > oPanl.Visible = False
    >
    > oTD2.Text = "Whatever Two" ' Row 2
    > oTR2.Controls.Add(oTD2)
    > oPanl.Controls.Add(oTR2) ' Add a PANEL ( = <div id="myPanel">) generates
    > an error on the next row.
    > oTbl.Controls.Add(oPanl) ' <<<<<<< 'Table' cannot have children of type
    > 'Panel'.
    > ' -------------------------------
    >
    > ' So the question is:
    > ' How can I dynamically generate a <div> so I can Hide a row?
    >
    > <table>
    > <tr>
    > <td>Whatever One</td>
    > </tr>
    > <div id="myPanel"> << how do I do this in CODE ?
    > <tr>
    > <td>Whatever Two</td>
    > </tr>
    > </div>
    > <table>
    >
    >
    > Thanks
    > ~Jennifer~
    >
     
    sloan, Mar 10, 2009
    #2
    1. Advertising

  3. Jennifer Mathews

    bruce barker Guest

    this will not work, a div cannot span <td>'s

    -- bruce (sqlwork.com)

    sloan wrote:
    > The error looks correct to me: You can't just throw in a <div> in the
    > middle of a table.
    >
    >
    >
    > This would be what you're after I think:
    >
    >
    >
    > <table>
    > <tr>
    > <td>Whatever One</td>
    > </tr>
    >
    > <tr><td>
    >
    > <div id="myPanel">
    >
    > </td></tr>
    >
    >
    > <tr>
    > <td>Whatever Two</td>
    > </tr>
    > </div>
    > <table>
    >
    >
    > "Jennifer Mathews" <> wrote in message
    > news:...
    >> ' The <table> has two rows.
    >> Dim oTbl As New Table
    >> Dim oTR1 As New TableRow
    >> Dim oTR2 As New TableRow
    >> Dim oTD1 As New TableCell
    >> Dim oTD2 As New TableCell
    >>
    >> oTD1.Text = "Whatever One" ' Row 1
    >> oTR1.Controls.Add(oTD1)
    >> oTbl.Controls.Add(oTR1)
    >>
    >> oTD2.Text = "Whatever Two" ' Row 2
    >> oTR2.Controls.Add(oTD2)
    >> oTbl.Controls.Add(oTR2)
    >>
    >> plchld_One.Controls.Add(oTbl) ' plchld_One is a PlaceHolder control on
    >> the page.
    >> ' This all works fine.
    >> ' -------------------------------
    >>
    >> ' just changing the code above a bit.
    >> Dim oPanl As New Panel
    >> oPanl.ID = "myPanel"
    >> oPanl.Visible = False
    >>
    >> oTD2.Text = "Whatever Two" ' Row 2
    >> oTR2.Controls.Add(oTD2)
    >> oPanl.Controls.Add(oTR2) ' Add a PANEL ( = <div id="myPanel">) generates
    >> an error on the next row.
    >> oTbl.Controls.Add(oPanl) ' <<<<<<< 'Table' cannot have children of type
    >> 'Panel'.
    >> ' -------------------------------
    >>
    >> ' So the question is:
    >> ' How can I dynamically generate a <div> so I can Hide a row?
    >>
    >> <table>
    >> <tr>
    >> <td>Whatever One</td>
    >> </tr>
    >> <div id="myPanel"> << how do I do this in CODE ?
    >> <tr>
    >> <td>Whatever Two</td>
    >> </tr>
    >> </div>
    >> <table>
    >>
    >>
    >> Thanks
    >> ~Jennifer~
    >>

    >
    >
     
    bruce barker, Mar 11, 2009
    #3
  4. Jennifer Mathews

    Logan S. Guest

    <Snip>

    If your objective is to simply hide the row, you can do it this way:

    <tr runat="server" ID="MyRow" Visible="true">...

    Then, in the code-behind you can access the row as a server-side generic
    html object, and set it's .visible property, like this:

    MyRow.Visible = false;

    Any time you add the runat="server" attribute to an HTML element, you can
    then access it in your C# code-behind and control basic properties,
    including .Visible.

    HTH
     
    Logan S., Mar 11, 2009
    #4
  5. Thanks to everyone for helping. A true education is starting.

    "Jennifer Mathews" <> wrote in message
    news:...
    >' The <table> has two rows.
    > Dim oTbl As New Table
    > Dim oTR1 As New TableRow
    > Dim oTR2 As New TableRow
    > Dim oTD1 As New TableCell
    > Dim oTD2 As New TableCell
    >
    > oTD1.Text = "Whatever One" ' Row 1
    > oTR1.Controls.Add(oTD1)
    > oTbl.Controls.Add(oTR1)
    >
    > oTD2.Text = "Whatever Two" ' Row 2
    > oTR2.Controls.Add(oTD2)
    > oTbl.Controls.Add(oTR2)
    >
    > plchld_One.Controls.Add(oTbl) ' plchld_One is a PlaceHolder control on the page.
    > ' This all works fine.
    > ' -------------------------------
    >
    > ' just changing the code above a bit.
    > Dim oPanl As New Panel
    > oPanl.ID = "myPanel"
    > oPanl.Visible = False
    >
    > oTD2.Text = "Whatever Two" ' Row 2
    > oTR2.Controls.Add(oTD2)
    > oPanl.Controls.Add(oTR2) ' Add a PANEL ( = <div id="myPanel">) generates an error on
    > the next row.
    > oTbl.Controls.Add(oPanl) ' <<<<<<< 'Table' cannot have children of type 'Panel'.
    > ' -------------------------------
    >
    > ' So the question is:
    > ' How can I dynamically generate a <div> so I can Hide a row?
    >
    > <table>
    > <tr>
    > <td>Whatever One</td>
    > </tr>
    > <div id="myPanel"> << how do I do this in CODE ?
    > <tr>
    > <td>Whatever Two</td>
    > </tr>
    > </div>
    > <table>
    >
    >
    > Thanks
    > ~Jennifer~
    >
     
    Jennifer Mathews, Mar 11, 2009
    #5
    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. Replies:
    3
    Views:
    839
  2. Some One
    Replies:
    5
    Views:
    1,042
    Toby A Inkster
    Aug 9, 2003
  3. K Viltersten

    <div ... /> and <div ...></div>

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    814
  4. Dwayne Madsen

    Q: Div A inside Div B is larger than Div B

    Dwayne Madsen, Jun 1, 2005, in forum: Javascript
    Replies:
    1
    Views:
    246
    David Dorward
    Jun 1, 2005
  5. mscir
    Replies:
    3
    Views:
    363
    Martin Honnen
    Jun 26, 2005
Loading...

Share This Page