Home All Groups Group Topic Archive Search About

Menu Question: How to change background for every other root item

Author
3 May 2006 10:33 PM
va
I have a horizontal menu and at the toor leverl, I need to change every other
one's background color.  Assume, I have the following menu:
"A" "B" "C" "D"

And I want B and D to be black background white text when first displayed. 
I can see hwo to change all items through CSS but how do I change individual
menu items without changing all lt the same level?

Author
4 May 2006 5:33 AM
Kelly Leahy
Well,

The short answer is, I don't think there's an easy way.  However, here's
something you can do:

            <DynamicItemTemplate>
                <div style='width:100%;height:100%;background-color:<%#
Container.ItemIndex % 2 == 0 ? "Black" : "White" %>;color:<%#
Container.ItemIndex % 2 == 0 ? "White" : "Black" %>'><%# Eval("Text") %></div>
            </DynamicItemTemplate>

This goes into your Menu control's innerXml (i.e. the stuff between the
beginning and end tags of the asp:Menu control).

You'll need a lot of tweaking for this to act as nice as the original menu
template.  I'd try to infer the original template first, and then just add
this tweak to set the style in the DIVs.

Cheers,
Kelly

Show quoteHide quote
"va" wrote:

> I have a horizontal menu and at the toor leverl, I need to change every other
> one's background color.  Assume, I have the following menu:
> "A" "B" "C" "D"
>
> And I want B and D to be black background white text when first displayed. 
> I can see hwo to change all items through CSS but how do I change individual
> menu items without changing all lt the same level?
Author
4 May 2006 11:48 AM
va
Wow!  Pretty brilliant.  Thank you.