Solved

Trouble with diving column items correctly

Posted on 2011-09-23
1
135 Views
Last Modified: 2012-05-12
I am trying to divide the items between 3 columns evenly and leave the remainder in the 3rd column.   However my code below keeps putting the last item back into the first column.   If you want to see what's happening, go to www.medicouponmanager.com and check out the bottom of the "select your health condition" section.  The last item is put back into the first column for some reason.  I want it to stay in the last.  

My code is below.   How can I fix this so that it ends up in the last column?
writer.WriteBeginTag("ul")
                If isRoot Then
                    writer.WriteAttribute("class", "KartrisMenu")
                Else
                    writer.WriteAttribute("class", "KartrisSubMenu")
                End If
                writer.Write(HtmlTextWriter.TagRightChar)
                writer.Indent += 1

                For Each item As MenuItem In items
                	intCounter += 1
                    BuildItem(item, writer)


If intCounter = Cint(items.Count/3) And intCounter >= Cint((items.Count/3)-1) then
	writer.Write("</ul><ul class=""KartrisMenu hide_me"">")
	intCounter = 0
End if

                Next

                writer.Indent -= 1
                writer.WriteLine()
                writer.WriteEndTag("ul")
            End If

Open in new window

0
Comment
Question by:saturation
1 Comment
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 36592409
Your last item ("Yeast Infections") is being put into a ul of its own.

<li class="KartrisMenu-Leaf">

                        <a href="/Womens-Health__c-p-0-0-75.aspx" class="KartrisMenu-Link">
                              Women's Health</a>
                  </li></ul><ul class="KartrisMenu hide_me">
                  <li class="KartrisMenu-Leaf">
                        <a href="/Yeast-Infections__c-p-0-0-70.aspx" class="KartrisMenu-Link">
                              Yeast Infections</a>
                  </li>
            </ul>


It's because of this statement:

If intCounter = Cint(items.Count/3) And intCounter >= Cint((items.Count/3)-1) then
      writer.Write("</ul><ul class=""KartrisMenu hide_me"">")
      intCounter = 0
End if

You have 73 items. If you divide by 3, you get 24 with a remainder of 1. You don't have any code to otherwise deal with this remainder so it is being put into a new ul. There's no more room for a fourth column of list items on the page, so it's being put at the bottom left, thus it appears to be at the bottom of the first column.

I think it would look nicer if the extra list item was in the first column. I would do this. Outside your loop, create a boolean value, Dim firstColumn As Boolean=true and a variable that holds the items.Count, Dim allItems As Integer = items.Count. Then change this statement to:

If firstColumn then
        If intCounter = allItems + (allItems Mod 3) Then
            writer.Write("</ul><ul class=""KartrisMenu hide_me"">")
              firstColumn = false
              intCounter = 0
        End If
else
        If intCounter = allItems/3 Then
            writer.Write("</ul><ul class=""KartrisMenu hide_me"">")
            intCounter = 0
        End If
End if
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now