dynamicly build <div> in for each loop

wisien92

New member
Joined
Jul 16, 2014
Messages
1
Programming Experience
1-3
Hi
I try to
dynamically build a div layout depending on the data i send to view, I want make 2 rows of divs and when there is odd number of models sent to view i want the layout to close.

As you can see in the code every 2nd model or on last model i close </div> and start <div> every odd model so i assume it't always opened and closed right amount of times .... but when i uncomment the commented code there are errors ....
(if i am not mistaken something similar worked in with C# so i hope it's only synax error)

VB.NET:
@[COLOR=#00008B]For[/COLOR] [COLOR=#00008B]Each[/COLOR] procesData [COLOR=#00008B]In[/COLOR] Model

        curElement = curElement + [COLOR=#800000]1[/COLOR]
        elemNumb = elemNumb + [COLOR=#800000]1[/COLOR]

        [COLOR=#00008B]If[/COLOR] (curElement = [COLOR=#800000]1[/COLOR]) [COLOR=#00008B]Then[/COLOR]
            [COLOR=#808080]'@<div id="row">    !Comented[/COLOR]
        [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR]
        @<div id="row-element@elemNumb">
        @<h3>Element number @elemNumb</h3>
        @<h3>@procesData.Name</h3>
        @<h3>@procesData.Status.ToString</h3>
        @<br />
        @</div>

        [COLOR=#00008B]If[/COLOR] (curElement = Model.Count) [COLOR=#00008B]Then[/COLOR]
            [COLOR=#00008B]If[/COLOR] (elemNumb = [COLOR=#800000]1[/COLOR]) [COLOR=#00008B]Then[/COLOR]
                [COLOR=#808080]'@</div>    !comented[/COLOR]
            [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR]
        [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR]

        [COLOR=#00008B]If[/COLOR] (curElement = [COLOR=#800000]2[/COLOR]) [COLOR=#00008B]Then[/COLOR]
            [COLOR=#808080]'@</div>  !comented[/COLOR]
            elemNumb = [COLOR=#800000]0[/COLOR]
        [COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR]

[COLOR=#00008B]Next[/COLOR]

 
when i uncomment the commented code there are errors ....

Please never say that an error occurs without giving details, most importantly where the error occurs and what the error message is. Whether it seems significant or not, error messages and their locations are often a great place for us to start when trying to diagnose an issue. We can often work out the same thing but it takes time that we shouldn't have to spend when you have the information already.
 
Back
Top