Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am having a bit of difficulty in my logic and was wondering if anyone could help.

Basically I have an order list like below:

<ul>
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
<li>Item Four</li>
</ul>
<ul>
<li>Item Five</li>
<li>Item Six</li>
<li>Item Seven</li>
<li>Item Eight</li>
</ul>

I am iterate through a datatable and building up a string as I go. See Below

For i = 0 to dt.rows.count - 1
If i mod 3 = 0 then
str_val +="<ul>"
End If

str_val +="<li>Item One</li>"

If i mod 3 0 then
str_val +="</ul>"
End If
Next

The problem I am having is after the first group of iterations it closes the ordered list but then doesn't open it again.

Has anyone had a similiar problem? If so any help is much appreciated.

Regards
McGann
Posted
Comments
Sergey Alexandrovich Kryukov 21-Nov-11 21:26pm    
What does it mean: "it closes the ordered list but then doesn't open it again"? HTML element is HTML element, how can it be closed or opened "again"?
--SA

1 solution

Of course it will.
At start your loop you have i = 0
i mod 3 = 0 - you open <ul>
then add an element
and closed <ul> tag inside same iteration.

for next iteration you have i = 1
i mod 3 = 1 and it neither opens nor closes.

possible solution may look like this:

VB
For i = 0 to dt.rows.count - 1
      If i mod 3 = 2 then ' 2 is because it actually is 3 -1 
            str_val +="</ul>"
      End If

      If i mod 3 = 0 then
            str_val +="<ul>"
      End If

      str_val +="<li>Item One</li>"

      If i mod 3 0 then
            str_val +="</ul>"
      End If
Next

if dt.rows.count > 0 then
            str_val +="</ul>"
end if


By the way why are you using 3, if you want to have 4 items in a group you should use 4 (and 3 in the first check which closes the tag).
 
Share this answer
 
v2

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