Solved

Trouble with diving column items correctly

Posted on 2011-09-23
1
136 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.net VB.net Email  a webpage 3 30
Hidden Field Value 10 60
How to deploy to IIS 7 on 2008R2 server with DUO 2-step login? 2 33
Split in Javascript 5 30
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

25 Experts available now in Live!

Get 1:1 Help Now