asp.net.ph

Skip Navigation Links

Adding Menu Items Declaratively

Controls You Can Use on Web Forms   ASP.NET Navigation Controls   Menu Control


Basically, to create a working Menu control, you need to add the control to the page and define the menu items.

The below procedures show the minimum steps needed to display static data in a Menu control using declarative syntax.

To add a Menu control to a Web Forms page

  1. Declare an <asp:menu> element on the page. For syntax, see Menu Control Syntax.
  2. Optionally set the control’s base properties.
    <asp:menu id="myMenu"
       staticdisplaylevels="2"
       staticsubmenuindent="10" 
       target="_blank"  
       runat="server">
  3. Within the Menu declaration, declare an <Items> element.
  4. Within the <Items> element, define the <asp:MenuItem> elements you intend to display, specifying at the very least the required Text and NavigateUrl properties.
    • If the Menu will be used for site navigation, set each menu item’s NavigateUrl property
    • Otherwise, optionally set each menu item’s Value property, to store any additional data that you may want to pass to the postback event handler.
  5. To create submenu items, nest additional <asp:MenuItem> elements between the opening and closing <asp:MenuItem> tags of the parent menu item.

The below example shows the declarative markup for a statically-defined Menu control.

<asp:menu id="myMenu"
   staticdisplaylevels="2"
   staticsubmenuindent="10" 
   target="_blank"  
   runat="server">

   <items>
      <asp:menuitem text="Favorites">
         <asp:menuitem text="News">
            <asp:menuitem text="MSN" navigateurl="http://www.msn.com"/>
            <asp:menuitem text="Google News" navigateurl="http://news.google.com"/>
         </asp:menuitem>

         <asp:menuitem text="Tech News">
            <asp:menuitem text="ASP.NET" navigateurl="http://www.asp.net"/>
            <asp:menuitem text="Microsoft Learn" navigateurl="https://learn.microsoft.com/"/>
            <asp:menuitem text="asp.net.ph" navigateurl="http://asp.net.ph"/>
         </asp:menuitem>

         <asp:menuitem text="Shopping">
            <asp:menuitem text="Lazada" navigateurl="https://www.lazada.com"/>
            <asp:menuitem text="Shopee" navigateurl="https://shopee.ph/"/>
            <asp:menuitem text="AliExpress" navigateurl="https://www.aliexpress.com/"/>
         </asp:menuitem>
      </asp:menuitem>
   </items>

</asp:menu>

 Show me 

See Also

Adding Menu Items Programmatically   Binding a Menu Control to a Data Source



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note