Groups | Blog | Home
all groups > asp.net building controls > april 2004 >

asp.net building controls : Adding <div> tag programatically


ricky.arora NO[at]SPAM icn.siemens.com
4/1/2004 11:43:10 PM
Hi All,

I would like to add the <div> tag programatically from the code-behind
of my aspx file. Basically, I would like to a table to this <div>.
There are a number of tables which are created dynamically in the
code-behind. Each table should go to its own <div> tag.
The reason that I can't have the <div> tags in aspx is that the number
of the tables is unknown until runtime and each table should go into
its own <div> tag.
How is this possible?
Kevin Spencer
4/2/2004 9:07:15 AM
Use the ASP.Net Panel control, which renders a div on the client.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

[quoted text, click to view]

Martin Dechev
4/2/2004 12:46:26 PM
using System.Web.UI.HtmlControls;

HtmlGenericControl div1 = new HtmlGenericControl("div");
div1.ID = "div1";
// add whatever attributes you need, eg make it scrollable:
div1.Attributes["style"] = "overflow: auto; width: 400px; height: 150px;";

// initialize your table
HtmlTable table1 = new HtmlTable();
table1.ID = "table1";
//....

// add the table to the div:
div1.Controls.Add(table1);

// add it to some PlaceHolder:
placeHolder1.Controls.Add(div1);

Greetings
Martin
[quoted text, click to view]

AddThis Social Bookmark Button