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.
- Declare an <
asp:menu
> element on the page. For syntax, see Menu Control Syntax.
- Optionally set the control’s base properties.
<asp:menu id="myMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
target="_blank"
runat="server">
- Within the Menu declaration, declare an <Items> element.
- 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.
- 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
Adding Menu Items Programmatically Binding a Menu Control to a Data Source