asp.net.ph

Menu Class

System.Web.UI.WebControls Namespace


.NET Framework version 2.0

Displays a menu in a Web Forms page.

Menu Class Members

Collapse   Constructors

Visibility Constructor Parameters
public Menu ( )

Collapse   Fields

Visibility Name Type
public static MenuItemClickCommandName String

Collapse   Properties

Visibility Name Value Type Accessibility
public Controls ControlCollection [ Get ]
public DataBindings MenuItemBindingCollection [ Get ]
public DisappearAfter Int32 [ Get , Set ]
public DynamicBottomSeparatorImageUrl String [ Get , Set ]
public DynamicEnableDefaultPopOutImage Boolean [ Get , Set ]
public DynamicHorizontalOffset Int32 [ Get , Set ]
public DynamicHoverStyle Style [ Get ]
public DynamicItemFormatString String [ Get , Set ]
public DynamicItemTemplate ITemplate [ Get , Set ]
public DynamicMenuItemStyle MenuItemStyle [ Get ]
public DynamicMenuStyle SubMenuStyle [ Get ]
public DynamicPopOutImageTextFormatString String [ Get , Set ]
public DynamicPopOutImageUrl String [ Get , Set ]
public DynamicSelectedStyle MenuItemStyle [ Get ]
public DynamicTopSeparatorImageUrl String [ Get , Set ]
public DynamicVerticalOffset Int32 [ Get , Set ]
public IncludeStyleBlock Boolean [ Get , Set ]
public Items MenuItemCollection [ Get ]
public ItemWrap Boolean [ Get , Set ]
public LevelMenuItemStyles MenuItemStyleCollection [ Get ]
public LevelSelectedStyles MenuItemStyleCollection [ Get ]
public LevelSubMenuStyles SubMenuStyleCollection [ Get ]
public MaximumDynamicDisplayLevels Int32 [ Get , Set ]
public Orientation Orientation [ Get , Set ]
public PathSeparator Char [ Get , Set ]
public RenderingMode MenuRenderingMode [ Get , Set ]
public ScrollDownImageUrl String [ Get , Set ]
public ScrollDownText String [ Get , Set ]
public ScrollUpImageUrl String [ Get , Set ]
public ScrollUpText String [ Get , Set ]
public SelectedItem MenuItem [ Get ]
public SelectedValue String [ Get ]
public SkipLinkText String [ Get , Set ]
public StaticBottomSeparatorImageUrl String [ Get , Set ]
public StaticDisplayLevels Int32 [ Get , Set ]
public StaticEnableDefaultPopOutImage Boolean [ Get , Set ]
public StaticHoverStyle Style [ Get ]
public StaticItemFormatString String [ Get , Set ]
public StaticItemTemplate ITemplate [ Get , Set ]
public StaticMenuItemStyle MenuItemStyle [ Get ]
public StaticMenuStyle SubMenuStyle [ Get ]
public StaticPopOutImageTextFormatString String [ Get , Set ]
public StaticPopOutImageUrl String [ Get , Set ]
public StaticSelectedStyle MenuItemStyle [ Get ]
public StaticSubMenuIndent Unit [ Get , Set ]
public StaticTopSeparatorImageUrl String [ Get , Set ]
public Target String [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
protected AddAttributesToRender ( HtmlTextWriter writer ) Void
public DataBind ( ) Void
protected EnsureDataBound ( ) Void
public FindItem ( String valuePath ) MenuItem
protected GetDesignModeState ( ) IDictionary
protected LoadViewState ( Object state ) Void
protected OnBubbleEvent ( Object source , EventArgs e ) Boolean
protected OnDataBinding ( EventArgs e ) Void
protected OnMenuItemClick ( MenuEventArgs e ) Void
protected OnMenuItemDataBound ( MenuEventArgs e ) Void
public RenderBeginTag ( HtmlTextWriter writer ) Void
public RenderEndTag ( HtmlTextWriter writer ) Void
protected SaveViewState ( ) Object
protected SetDesignModeState ( IDictionary data ) Void
protected SetItemDataBound ( MenuItem node , Boolean dataBound ) Void
protected SetItemDataItem ( MenuItem node , Object dataItem ) Void
protected SetItemDataPath ( MenuItem node , String dataPath ) Void
protected TrackViewState ( ) Void

Collapse   Events

Multicast Name Type
multicast MenuItemClick MenuEventHandler
multicast MenuItemDataBound MenuEventHandler

Remarks

The Menu control is used to display a menu in a Web Forms page and is often used in combination with a SiteMapDataSource control for navigating a Web site. The Menu control supports the following features:

  • Data binding that allows the control's menu items to be bound to hierarchical data sources.
  • Site navigation through integration with the SiteMapDataSource control.
  • Programmatic access to the Menu object model to dynamically create menus, populate menu items, set properties, and so on.
  • Customizable appearance through themes, user-defined images, styles, and user-defined templates.

When the user clicks a menu item, the Menu control can either navigate to a linked Web page or simply post back to the server. If the NavigateUrl property of a menu item is set, the Menu control navigates to the linked page; otherwise, it posts the page back to the server for processing. By default, a linked page is displayed in the same window or frame as the Menu control. To display the linked content in a different window or frame, use the Target property of the Menu control.

NOTE: The Target property affects every menu item in the control. To specify a window or frame for an individual menu item, set the Target property of the MenuItem object directly.

The Menu control displays two types of menus: a static menu and a dynamic menu. The static menu is always displayed in a Menu control. By default, the menu items at the root level ( level 0 ) are displayed in the static menu. You can display additional menu levels ( static submenus ) within the static menu by setting the StaticDisplayLevels property. Menu items ( if any ) with a higher level than the value specified by the StaticDisplayLevels property are displayed in a dynamic menu. A dynamic menu appears only when the user positions the mouse pointer over the parent menu item that contains a dynamic submenu. Dynamic menus automatically disappear after a certain duration. Use the DisappearAfter property to specify the duration.

NOTE: A dynamic menu also disappears when the user clicks outside of the menu.

You can also limit the number of levels displayed in a dynamic menu by setting the MaximumDynamicDisplayLevels property. Menu levels higher than the specified value are discarded.

Menu Items

A Menu control is made up of a tree of menu items represented by MenuItem objects. Menu items at the top level ( level 0 ) are called root menu items. A menu item that has a parent menu item is called a child menu item. All root menu items are stored in the Items collection. Child menu items are stored in a parent menu item's ChildItems collection.

Each menu item has a Text and a Value property. The value of the Text property is displayed in the Menu control, while the Value property is used to store any additional data about the menu item, such as data passed to the postback event associated with the menu item. When clicked, a menu item can navigate to another Web page indicated by the NavigateUrl property.

NOTE: If the NavigateUrl property is not set for a menu item, the Menu control simply submits the page to the server for processing when the menu item is clicked.

You can also optionally display an image in a menu item by setting the ImageUrl property.

For more information on menu items, see MenuItem.

Static Data

The simplest data model of the Menu control is static menu items. To display static menu items using declarative syntax, first nest opening and closing <Items> tags between the opening and closing tags of the Menu control. Next, create the menu structure by nesting <asp:MenuItem> elements between the opening and closing <Items> tags. Each <asp:MenuItem> element represents a menu item in the control and maps to a MenuItem object. You can set the properties of each menu item by setting the attributes of its <asp:MenuItem> element. To create submenu items, nest additional <asp:MenuItem> elements between the opening and closing <asp:MenuItem> tags of the parent menu item.

Binding to Data

The Menu control can also be bound to data. You can use either of two methods to bind the Menu control to the appropriate data source type:

  • The Menu control can use any hierarchical data source control, such as an XmlDataSource control or a SiteMapDataSource control. To bind to a hierarchical data source control, set the DataSourceID property of the Menu control to the ID value of the data source control. The Menu control automatically binds to the specified data source control. This is the preferred method to bind to data.
  • The Menu control can also be bound to an XmlDocument object. To bind to this data source, set the DataSource property of the Menu control to the data source and then call the DataBind method.

When binding to a data source where each data item contains multiple properties ( such as an XML element with several attributes ), a menu item displays the value returned by the ToString method of the data item by default. In the case of an XML element, the menu item displays the element name, which shows the underlying structure of the menu tree but is not very useful otherwise. You can bind a menu item to a specific data item property by using the DataBindings collection to specify menu item bindings. The DataBindings collection contains MenuItemBinding objects that define the relationship between a data item and the menu item it is binding to. You can specify the criteria for binding and the data item property to display in the node. For more information on menu item bindings, see MenuItemBinding.

You cannot create empty nodes in a Menu control by setting the Text or TextField properties to the empty string ( "" ). Setting these properties to the empty string has the same effect as not setting the properties. In that case, the Menu control creates a default binding using the DataSource property. For more information, see Web Page Data Binding Techniques.

For examples illustrating use of this control, see the individual member types of this class. For syntax information, see Menu in ASP.NET Syntax for Web Controls.

See Also

ASP.NET Navigation Controls   Menu Web Server Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

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

You can help support asp.net.ph