Static menu using asp:menu control

December 6, 2007 at 12:25 pm (.NET, ASP.NET, Web Design)

Last week i explored asp menu control and found it very useful to build the menu. The asp menu control can be used to display the menu vertically or horizontally. Menu items need to be displayed under the <items> section. Each menuitem is specified using the <asp:menuitem> tag. Multiple level menus can be easily designed using the asp menu control. The code i designed for the menu is shown below:-

<asp:Menu ID=”Menu1″ Orientation = “Vertical” runat=”server” BackColor=”#FFFFFF” BorderColor=”#F57F2C” BorderWidth=”1px” DynamicHorizontalOffset=”2″ StaticSubMenuIndent=”10px” >


<DynamicMenuStyle BackColor=”White” BorderColor=”#F57F2C” BorderWidth=”1px” />


<StaticMenuItemStyle BorderColor=”#F57F2C” BorderWidth=”1px” HorizontalPadding=”5px” VerticalPadding=”2px” />


<DynamicMenuItemStyle BorderColor=”#F57F2C” BorderWidth=”1px” HorizontalPadding=”5px” VerticalPadding=”2px” Font-Bold = “true” Font-Italic = “true” Font-Names = “verdana” Font-Size = “small” />


<StaticSelectedStyle BackColor=”#F57F2C” BorderColor=”#F57F2C” BorderWidth=”1px” ForeColor=”White” />


<DynamicSelectedStyle BackColor=”#F57F2C” BorderColor=”#F57F2C” BorderWidth=”1px” ForeColor=”White”/>


<StaticHoverStyle BackColor=”#F57F2C” BorderColor=”#F57F2C” BorderWidth=”1px” ForeColor=”White” />


<DynamicHoverStyle BackColor=”#F57F2C” ForeColor=”White”/>
<Items>

<asp:MenuItem Text=”Page 1″ NavigateUrl=”Page1.aspx”>
<asp:MenuItem Text=”Page 1-1″ NavigateUrl=”Page1-1.aspx”/>
<asp:MenuItem Text=”Page 1-2″ NavigateUrl=”Page1-2.aspx”/>
</asp:MenuItem>
<asp:MenuItem Text=”Page 2″ NavigateUrl=”Page2.aspx”>
<asp:MenuItem Text=”Page 2-1″ NavigateUrl=”Page2-1.aspx”/>
<asp:MenuItem Text=”Page 2-2″ NavigateUrl=”Page2-2.aspx”/>
</asp:MenuItem>
<asp:MenuItem Text=”Page 3″ NavigateUrl=”Page3.aspx”>
<asp:MenuItem Text=”Page 3-1″ NavigateUrl=”Page3-1.aspx”/>
<asp:MenuItem Text=”Page 3-2″ NavigateUrl=”Page3-2.aspx”/>
</asp:MenuItem>

</Items>
</asp:Menu>

you can view the menu i designed below:-

Menu using aspmenu control

Important Attributes :-

=======================

Orientation attribute : The orientation attribute specifies whether the menu need to be displayed vertically or horizontally.

DynamicHorozontalOffset attribute : It specifies number of pixels to shift a dynamic menu horizontally relative to its parent menu item. The default is 0.

StaticSubMenuIndent attribute : Gets or sets the amount of space, in pixels, to indent submenus within a static menu.

Important Sections:-

=====================

StaticMenuStyle :- It specifies the style for the group of static menu elements in the same level.

DynamicMenuStyle :- It specifies the style for the group of dynamic menu elements in the same level.

StaticMenuItemStyle :- It specifies the style for each static menu item.

DynamicMenuItemStyle :- It specifies the style for each dynamic menu item.

StaticHoverStyle :- It specifies the style when the mouse hovers over the static menu item.

DynamicHoverStyle :- It specifies the style when the mouse hovers over the dynamic menu item.

StaticSelectedStyle :- It specifies the style for the selected static menu item in the asp menu control.

DynamicSelectedStyle :- It specifies the style for the selected dynamic menu item in the asp menu control.

Item :- It specifies the MenuItems in the menu.

Note:-
=======

After exploring this control i found that

Only one menuitem can be selected at a time. Even if we set a particular menuitems as selected programatically the last selected one will be selected.

The parent menuitem will not be selected when we move to the child menuitem.

Advertisements

4 Comments

  1. gnlife said,

    the asp menu is best when u want to generate a dynamic menu based on roles :d

  2. mould removal in toronto said,

    Just curious how did you build the layout of this post?
    Is there a unique website template you got? Please let me know to see if I’ll consider it for my personal blog also, thank you!

  3. [RESOLVED]static site with dynamic menu | ASP Questions & Answers said,

  4. [RESOLVED]static site with dynamic menu | ASP Web Form Data Control said,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: