Giri
Giri

Reputation: 941

How to apply the style for selected menu item in ASP.NET 3.5?

I need to set the background for the currently active menu item?

I have used these

 <StaticSelectedStyle CssClass="selectedMenuItem" />

CSS:

 .DivLeftContent .selectedMenuItem:visited
  {
      background-color:#FBB2F7 ! important;
  } 

It is not worked.. Then i used this.

CSS:

.MenuItem a.static.selected
{
background-color:Black ! important;
}

OnPageLosd of master page

   string path = Request.AppRelativeCurrentExecutionFilePath;
   foreach (MenuItem item in menuItem.Items)
   {
     item.Selected = item.NavigateUrl.Equals(path,StringComparison.InvariantCultureIgnoreCase);
   }

This is also not working..

I am using ASP.NET 3.5 and creating menu in master page.

Help me..

Thanks..

Upvotes: 0

Views: 3809

Answers (2)

pibcat
pibcat

Reputation: 94

There is a tricky way to do that..when you select a menu item on the code behind of the master page, check for the local URL path and change the background of the selected menu item based on Local URL which is Unique. and call that method in div class property using Eval Expression so that it will change the background of the selected menu item dynamically..

Let me know if you need more detail..

Upvotes: 2

Aghilas Yakoub
Aghilas Yakoub

Reputation: 29000

You can try with DynamicSelectedStyle proprerty

Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.menu.dynamicselectedstyle.aspx

Upvotes: 0

Related Questions