Solved

Trouble with diving column items correctly

Posted on 2011-09-23
1
139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add a Condition in ASP Repeater 6 47
asp web application 3 42
Asp.Net Session Question 2 36
ASP.NET Built-In Report Creator / Viewer 5 23
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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