Groups | Blog | Home
all groups > asp.net webcontrols > june 2004 >

asp.net webcontrols : Add Inner HTML to Table?


Kris
6/28/2004 10:37:01 AM
try this

HtmlTableCell testCell = new HtmlTableCell;
testCell.Controls.Add( new LiteralControl("<beh1:behDiv>" );
testRow.Add(testCell); 'add the cell to the row
'then add the row to the table

sorry, i don't use C#

[quoted text, click to view]
localhost
6/28/2004 1:28:40 PM

I need to add a behavior to a table and its rows. I cannot determine
how to do this. My code looks like this:


HtmlTable testTable = newHtmlTable();
HtmlTableRow testRow = new HtmlTableRow();
testTable.Controls.Add(testRow );
testRow.Controls.Add( new LiteralControl("<beh1:behDiv>" );

This compiles fine, but at runtime I get the error:

'HtmlTableRow' cannot have children of type 'LiteralControl'.


How can I write HyperText behavior code (or any other "raw HTML") into
my table row?

Thanks.




Please note that I must do all of this in the code-behind and not in
the .aspx page template.
localhost
6/28/2004 2:06:05 PM


Thanks, but that actually adds a <TD> inside the <TR>. I need to put
my HTC behavior between the <TR> and <TD>...


On Mon, 28 Jun 2004 10:37:01 -0700, "Kris"
[quoted text, click to view]
[snip]
Scott G.
6/28/2004 4:12:18 PM

Then create a subclass of HtmlTableCell... In C#

internal class HTCHtmlTableCell : HtmlTableCell
{
internal HTCHtmlTableCell(string htc)
{ HTC =3D htc; }

private strin m_htc;
public string HTC
{ get { return m_htc; }
set { m_htc =3D value; }
}

protected override void Render(HtmlTextWriter writer)
{ writer.Write(HTC); }
}

....
row.Cells.Add(new HTCHtmlTableCell("you htc here"));
[quoted text, click to view]


Thanks, but that actually adds a <TD> inside the <TR>. I need to put
my HTC behavior between the <TR> and <TD>...


On Mon, 28 Jun 2004 10:37:01 -0700, "Kris"
[quoted text, click to view]
ashelley NO[at]SPAM inlandkwpp.com
6/28/2004 7:48:26 PM
On Mon, 28 Jun 2004 14:06:05 -0400, localhost <primpilus@cohort.ces>
[quoted text, click to view]

that is usually not a valid thing to do.

Robert Koritnik
6/29/2004 9:42:00 AM
You could also create the whole table as LiteralControls and not as
HtmlTable... Or GenericControl.

Hmm. Have you tried to use Table class instead of HtmlTable instead?
Firsttry this. Scott's approach is most advanced and very good. The most
nasty and "not really asp.net" like is my forst preposition.

--
RobertK
{ Clever? No just smart. }

[quoted text, click to view]

AddThis Social Bookmark Button