Asp.Net Menu | Hide The Last Seperator Image

Sometimes it’s hard to understand why things work different in Asp.Net. Maybe that’s because I’m not so expert with it. Though, it makes no sense to me not to be able to seperate Asp.Net Menu items with chars like ‘|’ or ‘-‘ etc. Allright, we create little seperator images but when we do it, it either adds before all elements or after. Like “Home | News | Contact |”. What’s the sense of last seperator? What is it seperating actually? I never seen such usage…

Anyway, there’s always a way to do what we want but I just don’t know why we have to cross that bridge.

Here’s the code that hides last menu item’s seperator image so that we have a normal menu:

protected void myMenu_PreRender(object sender, EventArgs e)
{
    //We define seperator image for all menu items except the last (Items.Count -1)
    for (int i = 0; i < myMenu.Items.Count-1; i++)
    {
        myMenu.Items[i].SeparatorImageUrl = "~/Images/MasterPage/menu-seperator.png";
    }
}
Post a comment