Link to home
Start Free TrialLog in
Avatar of JCWEBHOST
JCWEBHOST

asked on

asp menu

hey guys i need to develop a menu using asp control to look like this:

 User generated image
i can use css friendly, the hard part is the alternating colours.

please help?
Avatar of royend
royend
Flag of Norway image

When you are looping through your menu-items, set the color by using the modulo operator:

int count = 0;
foreach(MenuItem m in Menu)
{
   if(count % 2 == 0)
    {
        //set color = blue
    }
    else
    {
        //set color = yellow
    }

   count++;
}

Open in new window

Avatar of JCWEBHOST
JCWEBHOST

ASKER

must i code in c#? couse i can.

just that i do not know were to start?
Some info on the modulo operator:
It is a mathematical operator that gives you the remainder of a division.

E.g. if you divide 3 by 2, you get 1.5, or a remainder of 1 which is what the modulo operator would return.
Furthermore, if you divide 5 by 2, you get 2.5, and still the modulo function would return 1.
However, dividing 4 by 2, you get 2.0, and thus a remainder = 0, and modulo = 0.

In C#:
0 % 2 = 0
1 % 2 = 1
2 % 2 = 0
3 % 2 = 1
4 % 2 = 0
and so on...

you can of course divide by other numbers:
0 % 3 = 0
1 % 3 = 1
2 % 3 = 2
3 % 3 = 0
4 % 3 = 1
and so on....

If you are using VB you may use Mod instead of %:
0 Mod 3 = 0
How do you code your menu today? Are you using ASP.NET grid or repeater, or just HTML?
how to set the menu background colour?

            Menu Menu = (Menu)(FindControl("Menu"));
            Menu.Items.Add(new MenuItem("Home", "", "", "#"));
            Menu.Items.Add(new MenuItem("Kids Playground Equipment", "", "", "#"));
            Menu.Items.Add(new MenuItem("Kids Entertainment", "", "", "#"));
            Menu.Items.Add(new MenuItem("Contact Us", "", "", "#"));
ASKER CERTIFIED SOLUTION
Avatar of royend
royend
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial