• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

asp menu

hey guys i need to loop through my asp menu and make the items background alternate

e.g

red / green / red / green

i need to do it in c# code
0
JCWEBHOST
Asked:
JCWEBHOST
  • 3
1 Solution
 
APoPhySptCommented:
Do yuo want to change the entire menu color at once or have each option have a different color?
0
 
JCWEBHOSTAuthor Commented:
just each menu item like

home = red
services = green
products = red
0
 
APoPhySptCommented:
Hi.. as far as I know using '<asp:Menu' it cannot be done... perhaps you should try considering writing your own menu using just html tags with which you can have a lot more control over what's going on.

Take a look at the following tutorial on how to make a simple menu using <ul> & <li>:
http://jamesowers.co.uk/css-tutorials/50/horizontal-css-list-menu/

0
 
APoPhySptCommented:
but if you really want to change the Background color through C# code, using <ul> <li> you can do this:

Css File:
 
.navMenu ul
{
    list-style: none;
    padding: 0;
    margin: 0;
    vertical-align:middle;
    text-align:center;
} 

.navMenu ul li
{
    height:25px;
    width:75px;
    vertical-align:middle;
}

.Red
{
    background-color: Red;
}

.Green
{
    background-color:Green;
}

Open in new window


Html Code ( goes into the *.aspx ):
 
<div class="navMenu" runat="server">
        <ul runat="server">
            <li runat="server" id="li1"><a href="#">Services</a></li>
            <li runat="server" id="li2"><a href="#">About us</a></li>
            <li runat="server" id="li3"><a href="#">Contact us</a></li>
        </ul>
    </div>

Open in new window


The code itself to change colors ( *.aspx.cs ):
 
li1.Attributes.Remove("class");
    li1.Attributes.Add("class", "Red");

    li2.Attributes.Remove("class");
    li2.Attributes.Add("class", "Green");

    li3.Attributes.Remove("class");
    li3.Attributes.Add("class", "Red");

Open in new window


perhaps not as pretty but should do the job

cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now