ARTICLE

How to change the selected color of the menu item in ASP. NET using VB.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET June 29, 2011
Here, we will see how to change the selected color of the menu item.
Download Files:
 
Reader Level:

Here, we will see how to change the selected color of the menu item. When we Select any menu item that should be highlight like the text becomes bold and change background color.

Now add 1 Master Page and its Content Pages. Select the Master Pages to Content Pages.

1. Home.aspx
2. TrainingPage.aspx
3. JobPage.aspx
4. ArticlePage.aspx
5. MasterPage.master

In the Master Page, add the following HTML.

<head runat="server">

   <title></title>

   <asp:ContentPlaceHolder id="head" runat="server">

   </asp:ContentPlaceHolder>

   <link href="StyleSheet.css" rel="stylesheet"

       type="text/css" />

</head>

<body >

   <form id="form1" runat="server" >

   <div>  

   <div id="topNavigation" align="center">

   <asp:Menu ID="topMenu" runat="server" DataSourceID="topMenuData"

       MaximumDynamicDisplayLevels="0" Orientation="Horizontal">

       <StaticMenuItemStyle CssClass="MenuItemStyle" />

       <StaticSelectedStyle CssClass="SelectedStyle" />

       <StaticHoverStyle CssClass="HoverStyle" />

   </asp:Menu>

</div> 

   <br />

      </div>

   <div >

       <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">      

       </asp:ContentPlaceHolder>

   </div>

   <asp:SiteMapDataSource ID="topMenuData" runat="server" ShowStartingNode="false" />

   </form>

</body>

</html>

 

 

In the above HTML code we drag a sitemap control and set the property howStartingNode="false".

 

Now we create CSS.

MenuItemStyle - MenuItemStyle is the Style of the item which is not selected.
SelectedStyle - SelectedStyle is the Style of the item which is selected.
HoverStyle - HoverStyle is the hover Style of the item.

 

CSS code

 

#topNavigation

{

   width: 100%;

   background-color:red;

   vertical-align: bottom;

   padding: 0;

   margin: 0;

   z-index: 0;

   height: 30px;

}

   

   .MenuItemStyle

{

   width: 89px;

   background-color:black;

   border: solid 1px #000;

   color: #CCFF33;

   text-align: center;

   height: 30px;

}

   .SelectedStyle

{

   background-color:orange;

   color: #003300;

   border-bottom: solid 1px #eee;

   z-index: 100;

}

   .HoverStyle

{

   background-color:orange;

}

 

 

Now Add the following code with sitemap control.

 

<?xml version="1.0" encoding="utf-8" ?>

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

    <siteMapNode url="" title="Main" description="">

      <siteMapNode url="Home.aspx" title="HomePage" description="Redirects To HomePage" />

        <siteMapNode url="ArticlePage.aspx" title="Article Page"  description="Redirects To ArticlePage" >

       

        </siteMapNode>

      <siteMapNode url="TrainingPage.aspx" title="Training" description="Redirects To Training Page" />

       <siteMapNode url="JobPage.aspx" title="JobPage" description="Redirects To Job Page" />   

       </siteMapNode>

</siteMap>

 

Now run application and test it.

m1.gif

Figure1

Now click on the menu item.

m2.gif

Figure2

Note: You can see a demo of this article by downloading this application.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor