Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How do I add nested DIV's dynamically from the vb side
Need this his to build from the vb side:

HTML
<div class="wrapper">
                
                <div class="container-fluid">
                    <div id="heading" class="page-header">
                    </div>
                    <div class="row-fluid">
                        <div class="span13">
                            <div class="widget">
                                <div class="widget-title">
                                    <div class="icon"></div>
              </div>
                              
                                <div class="widget-content">
                                    <div id="chart5_div" class="chart"></div>
                     
                                    
                                    <div class="clearfix"></div>
                                </div>
                             
                            </div>
                    
                        </div>
                       
                    </div>
                   
                  
                </div>
               
            </div>


Thank you
Posted
Comments
Maarten Kools 4-Feb-14 7:40am    
What have you tried so far?
Asgard25 4-Feb-14 7:48am    
Dim div1 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div1.Attributes("Class") = "row-fluid"
PlaceHolder1.Controls.Add(div1)

Dim div2 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div2.Attributes("Class") = "span13"
PlaceHolder1.Controls.Add(div2)

Dim div3 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div3.Attributes("Class") = "widget"
PlaceHolder1.Controls.Add(div3)

Dim div4 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div4.Attributes("Class") = "widget-title"
PlaceHolder1.Controls.Add(div4)

Dim div5 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div5.Attributes("Class") = "widget-content"
PlaceHolder1.Controls.Add(div5)

Dim dynDiv As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
dynDiv.ID = lcount
dynDiv.Attributes("Class") = "chart"
dynDiv.InnerHtml = "I was created using Code Behind"
PlaceHolder1.Controls.Add(dynDiv)

Dim div6 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div6.Attributes("Class") = "clearfix"
PlaceHolder1.Controls.Add(div6)
Maarten Kools 4-Feb-14 7:51am    
Looks fine, apart from the fact you're adding everything to the PlaceHolder1.Controls collection, so you're not nesting the divs. Each HtmlGenericControl will have its own Controls collection, so child elements can be added to that. For example:

Dim div1 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div1.Attributes("Class") = "row-fluid"
PlaceHolder1.Controls.Add(div1)

Dim div2 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div2.Attributes("Class") = "span13"
div1.Controls.Add(div2) <-- Instead of adding this div to the PlaceHolder1 control, add it to div1.
Asgard25 4-Feb-14 8:06am    
Thank you, that worked great !
Maarten Kools 4-Feb-14 8:08am    
You're welcome!

1 solution

As per request from JoCodes :)

Looks fine, apart from the fact you're adding everything to the PlaceHolder1.Controls collection, so you're not nesting the divs. Each HtmlGenericControl[^] will have its own Controls[^] collection, so child elements can be added to that. For example:
VB
Dim div1 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div1.Attributes("Class") = "row-fluid"
PlaceHolder1.Controls.Add(div1)

Dim div2 As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
div2.Attributes("Class") = "span13"
div1.Controls.Add(div2) ' Instead of adding this div to the PlaceHolder1 control, add it to div1.
 
Share this answer
 
Comments
JoCodes 4-Feb-14 9:35am    
And my 5
Maarten Kools 4-Feb-14 9:36am    
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900