Dilip Solanki

Dilip Solanki

  • NA
  • 72
  • 14.9k

How to add nested div using c#?

Feb 4 2013 2:40 AM
good morning frndz....

I m trying to create div within div using c# code, but when i m trying to insert parent div, its properly created but when i m going to insert its child div its not created.


For e.g my code as below:

Div related css properties is coming from database:


My Code as below:

HtmlGenericControl dynDiv = new HtmlGenericControl("DIV");
                dynDiv.ID = (string)reader1["div_id"];
                dynDiv.Style.Add("width", (string)reader1["width"]);
                dynDiv.Style.Add("height", (string)reader1["height"]);
                dynDiv.Style.Add("background-color", (string)reader1["background_color"]);
                dynDiv.Style.Add("top", (string)reader1["div_top"]);
                dynDiv.Style.Add("left", (string)reader1["div_left"]);
                dynDiv.Style.Add("margin-left", (string)reader1["margin_left"]);
                dynDiv.Style.Add("margin-top", (string)reader1["margin_top"]);
                dynDiv.Style.Add("float", (string)reader1["div_float"]);
                dynDiv.InnerHtml = (string)reader1["innerhtml"];
                dynDiv.Visible = true;
                this.Controls.Add(dynDiv);



as per the above code my parent div created in page body.
But now i want to add one more div into this recently created div......

I want to create my all div in runtime. I dont want to add any single div in design time.

For e.g

<div id="super">
<div id="left"></div>
<div id="right"></div>
</div>


this structure i want to create in runtime..




how can i do it...

Plz help me .....................

Answers (1)