Adding <div> tag programatically

D

DJ Dev

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?
Thanks.
 
M

Martin Dechev

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
 
K

Kevin Spencer

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.
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top