Dynamically creating <DIV> statement

J

Jennifer Mathews

' 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~
 
S

sloan

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>
 
L

Logan S.

<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
 

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,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top