.NET Framework Class Library Menu Class Displays a menu in an ASP.NET Web page.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
<ControlValuePropertyAttribute("SelectedValue")> _
Public Class Menu _
Inherits HierarchicalDataBoundControl _
Implements IPostBackEventHandler, INamingContainer
[ControlValuePropertyAttribute("SelectedValue")]
public class Menu : HierarchicalDataBoundControl, IPostBackEventHandler, INamingContainer
[ControlValuePropertyAttribute(L"SelectedValue")]
public ref class Menu : public HierarchicalDataBoundControl,
IPostBackEventHandler, INamingContainer
[<ControlValuePropertyAttribute("SelectedValue")>]
type Menu =
class
inherit HierarchicalDataBoundControl
interface IPostBackEventHandler
interface INamingContainer
end
The Menu type exposes the following members.

Constructors
|
| Name | Description |
|---|
.gif) | Menu | Initializes a new instance of the Menu class. | Top

Methods
|
| Name | Description |
|---|
.gif) | AddAttributesToRender | Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter object. (Overrides WebControl..::.AddAttributesToRender(HtmlTextWriter).) | .gif) | AddedControl | Called after a child control is added to the Controls collection of the Control object. (Inherited from Control.) | .gif) | AddParsedSubObject | Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object. (Inherited from Control.) | .gif) | ApplyStyle | Copies any nonblank elements of the specified style to the Web control, overwriting any existing style elements of the control. This method is primarily used by control developers. (Inherited from WebControl.) | .gif) | ApplyStyleSheetSkin | Applies the style properties defined in the page style sheet to the control. (Inherited from Control.) | .gif) | BuildProfileTree | Infrastructure. Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page. (Inherited from Control.) | .gif) | ClearCachedClientID | Infrastructure. Sets the cached ClientID value to nullNothingnullptra null reference (Nothing in Visual Basic). (Inherited from Control.) | .gif) | ClearChildControlState | Deletes the control-state information for the server control's child controls. (Inherited from Control.) | .gif) | ClearChildState | Deletes the view-state and control-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearChildViewState | Deletes the view-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Sets the ClientIDMode property of the current control instance and of any child controls to Inherit. (Inherited from Control.) | .gif) | ConfirmInitState | Sets the initialized state of the data-bound control. (Inherited from BaseDataBoundControl.) | .gif) | CopyBaseAttributes | Copies the properties not encapsulated by the Style object from the specified Web server control to the Web server control that this method is called from. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | CreateChildControls | Creates the child controls of a Menu control. (Overrides Control..::.CreateChildControls()()().) | .gif) | CreateControlCollection | Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control. (Inherited from Control.) | .gif) | CreateControlStyle | Creates the style object that is used internally by the WebControl class to implement all style related properties. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | DataBind()()() | Binds the data source to the Menu control. This method cannot be inherited. (Overrides BaseDataBoundControl..::.DataBind()()().) | .gif) | DataBind(Boolean) | Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event. (Inherited from Control.) | .gif) | DataBindChildren | Binds a data source to the server control's child controls. (Inherited from Control.) | .gif) | Dispose | Enables a server control to perform final clean up before it is released from memory. (Inherited from Control.) | .gif) | EnsureChildControls | Determines whether the server control contains child controls. If it does not, it creates child controls. (Inherited from Control.) | .gif) | EnsureDataBound | Verifies that the menu control requires data binding and that a valid data source control is specified before calling the DataBind method. (Overrides BaseDataBoundControl..::.EnsureDataBound()()().) | .gif) | EnsureID | Creates an identifier for controls that do not have an identifier assigned. (Inherited from Control.) | .gif) | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | .gif) | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | .gif) | FindControl(String) | Searches the current naming container for a server control with the specified id parameter. (Inherited from Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method. (Inherited from Control.) | .gif) | FindItem | Retrieves the menu item at the specified value path. | .gif) | Focus | Sets input focus to a control. (Inherited from Control.) | .gif) | GetData | Retrieves a HierarchicalDataSourceView object that the data-bound control uses to perform data operations. (Inherited from HierarchicalDataBoundControl.) | .gif) | GetDataSource | Retrieves the IHierarchicalDataSource that the data-bound control is associated with, if any. (Inherited from HierarchicalDataBoundControl.) | .gif) | GetDesignModeState | Retrieves the design-time state of the Menu control. (Overrides Control..::.GetDesignModeState()()().) | .gif) | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | .gif) | GetRouteUrl(Object) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(String, Object) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetType | Gets the Type of the current instance. (Inherited from Object.) | .gif) | GetUniqueIDRelativeTo | Returns the prefixed portion of the UniqueID property of the specified control. (Inherited from Control.) | .gif) | HasControls | Determines if the server control contains any child controls. (Inherited from Control.) | .gif) | HasEvents | Returns a value indicating whether events are registered for the control or any child controls. (Inherited from Control.) | .gif) | IsLiteralContent | Infrastructure. Determines if the server control holds only literal content. (Inherited from Control.) | .gif) | LoadControlState | Loads the state of the properties in the Menu control that need to be persisted. (Overrides Control..::.LoadControlState(Object).) | .gif) | LoadViewState | Loads the previously saved view state of the Menu control. (Overrides WebControl..::.LoadViewState(Object).) | .gif) | MapPathSecure | Retrieves the physical path that a virtual path, either absolute or relative, maps to. (Inherited from Control.) | .gif) | MarkAsDataBound | Sets the state of the control in view state as successfully bound to data. (Inherited from HierarchicalDataBoundControl.) | .gif) | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | .gif) | MergeStyle | Copies any nonblank elements of the specified style to the Web control, but will not overwrite any existing style elements of the control. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | OnBubbleEvent | Infrastructure. Determines whether the event for the Menu control is passed up the page's user interface (UI) server control hierarchy. (Overrides Control..::.OnBubbleEvent(Object, EventArgs).) | .gif) | OnDataBinding | Raises the DataBinding event. (Overrides Control..::.OnDataBinding(EventArgs).) | .gif) | OnDataBound | Raises the DataBound event. (Inherited from BaseDataBoundControl.) | .gif) | OnDataPropertyChanged | Called when one of the base data source identification properties is changed, to re-bind the data-bound control to its data. (Inherited from HierarchicalDataBoundControl.) | .gif) | OnDataSourceChanged | Called when the IHierarchicalDataSource instance that the data-bound control works with raises the DataSourceChanged event. (Inherited from HierarchicalDataBoundControl.) | .gif) | OnInit | Infrastructure. Raises the Init event. (Overrides BaseDataBoundControl..::.OnInit(EventArgs).) | .gif) | OnLoad | Handles the Load event. (Inherited from HierarchicalDataBoundControl.) | .gif) | OnMenuItemClick | Raises the MenuItemClick event. | .gif) | OnMenuItemDataBound | Raises the MenuItemDataBound event. | .gif) | OnPagePreLoad | Sets the initialized state of the data-bound control before the control is loaded. (Inherited from HierarchicalDataBoundControl.) | .gif) | OnPreRender | Infrastructure. Raises the PreRender event. (Overrides BaseDataBoundControl..::.OnPreRender(EventArgs).) | .gif) | OnUnload | Raises the Unload event. (Inherited from Control.) | .gif) | OpenFile | Gets a Stream used to read a file. (Inherited from Control.) | .gif) | PerformDataBinding | Infrastructure. Binds the items from the data source to the menu items in the Menu control. (Overrides HierarchicalDataBoundControl..::.PerformDataBinding()()().) | .gif) | PerformSelect | Retrieves data from the associated data source. (Inherited from HierarchicalDataBoundControl.) | .gif) | RaiseBubbleEvent | Assigns any sources of the event and its information to the control's parent. (Inherited from Control.) | .gif) | RaisePostBackEvent | Processes an event raised when a form is posted to the server. | .gif) | RemovedControl | Called after a child control is removed from the Controls collection of the Control object. (Inherited from Control.) | .gif) | Render | Infrastructure. Renders the menu control on the client browser. (Overrides WebControl..::.Render(HtmlTextWriter).) | .gif) | RenderBeginTag | Adds tag attributes and writes the markup for the opening tag of the control to the output stream emitted to the browser or device. (Overrides WebControl..::.RenderBeginTag(HtmlTextWriter).) | .gif) | RenderChildren | Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client. (Inherited from Control.) | .gif) | RenderContents | Infrastructure. This member overrides RenderContents. (Overrides WebControl..::.RenderContents(HtmlTextWriter).) | .gif) | RenderControl(HtmlTextWriter) | Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled. (Inherited from Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object. (Inherited from Control.) | .gif) | RenderEndTag | Performs final markup and writes the HTML closing tag of the control to the output stream emitted to the browser or device. (Overrides WebControl..::.RenderEndTag(HtmlTextWriter).) | .gif) | ResolveAdapter | Gets the control adapter responsible for rendering the specified control. (Inherited from Control.) | .gif) | ResolveClientUrl | Gets a URL that can be used by the browser. (Inherited from Control.) | .gif) | ResolveUrl | Converts a URL into one that is usable on the requesting client. (Inherited from Control.) | .gif) | SaveControlState | Infrastructure. Saves the state of the properties in the Menu control that need to be persisted. (Overrides Control..::.SaveControlState()()().) | .gif) | SaveViewState | Saves the state of the Menu control. (Overrides WebControl..::.SaveViewState()()().) | .gif) | SetDesignModeState | Sets design-time data for the Menu control. (Overrides Control..::.SetDesignModeState(IDictionary).) | .gif) | SetItemDataBound | Sets the DataBound property of the specified MenuItem object with the specified value. | .gif) | SetItemDataItem | Sets the DataItem property of the specified MenuItem object with the specified value. | .gif) | SetItemDataPath | Sets the DataPath property of the specified MenuItem object with the specified value. | .gif) | SetRenderMethodDelegate | Infrastructure. Assigns an event handler delegate to render the server control and its content into its parent control. (Inherited from Control.) | .gif) | ToString | Returns a string that represents the current object. (Inherited from Object.) | .gif) | TrackViewState | Tracks view-state changes to the Menu control so they can be stored in the control's StateBag object. This object is accessible through the ViewState property. (Overrides WebControl..::.TrackViewState()()().) | .gif) | ValidateDataSource | Verifies that the object a data-bound control binds to is one it can work with. (Inherited from HierarchicalDataBoundControl.) | Top

Extension Methods

Fields

Explicit Interface Implementations
|
| Name | Description |
|---|
.gif) .gif) | IAttributeAccessor..::.GetAttribute | Infrastructure. Gets an attribute of the Web control with the specified name. (Inherited from WebControl.) | .gif) .gif) | IAttributeAccessor..::.SetAttribute | Sets an attribute of the Web control to the specified name and value. (Inherited from WebControl.) | .gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | For a description of this member, see IControlBuilderAccessor..::.ControlBuilder. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.GetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.SetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. For a description of this member, see IControlDesignerAccessor..::.SetOwnerControl. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | For a description of this member, see IControlDesignerAccessor..::.UserData. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | For a description of this member, see IDataBindingsAccessor..::.DataBindings. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | For a description of this member, see IDataBindingsAccessor..::.HasDataBindings. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | For a description of this member, see IExpressionsAccessor..::.Expressions. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | For a description of this member, see IExpressionsAccessor..::.HasExpressions. (Inherited from Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | For a description of this member, see IParserAccessor..::.AddParsedSubObject. (Inherited from Control.) | .gif) .gif) | IPostBackEventHandler..::.RaisePostBackEvent | Infrastructure. Processes an event raised when a form is posted to the server. | Top

Remarks
In this topic: IntroductionThe Menu control is used to display a menu in an ASP.NET Web 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 hierarchal 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 ItemsA 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 DataThe 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 DataThe Menu control can use any hierarchal data source control, such as an XmlDataSource control or a SiteMapDataSource control. To bind to a hierarchal 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. 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 Binding to Databases. Customizing the User InterfaceThere are many ways to customize the appearance of the Menu control. First, you can specify whether the Menu control is rendered horizontally or vertically by setting the Orientation property. You can also specify a different style (such as font size and color) for each of the menu item types. If you use cascading style sheets (CSS) to customize the appearance of the control, use either inline styles or a separate CSS file, but not both. Using both inline styles and a separate CSS file could cause unexpected results. For more information on using style sheets with controls, see ASP.NET Web Server Controls and CSS Styles. The following table lists the available menu item styles. Instead of setting the individual style properties, you can specify styles that are applied to menu items based on their level by using the following style collections. The first style in the collection corresponds to the style of the menu items at the first depth level in the menu tree. The second style in the collection corresponds to the style of the menu items at the second depth level in the menu tree, and so on. This is most often used to generate table of contents-style navigation menus where menu items at a certain depth should have the same appearance, regardless of whether they have submenus. Note |
|---|
If you use any of the level style collections listed in the previous table to define the style for the Menu control, these style settings override the individual menu item style properties. |
Another way to alter the appearance of the control is to customize the images displayed in the Menu control. You can specify your own custom image for the different parts of the control by setting the properties shown in the following table. Image property | Description |
|---|
DynamicBottomSeparatorImageUrl
| An optional image displayed at the bottom of a dynamic menu item to separate it from other menu items. |
DynamicPopOutImageUrl
| An optional image displayed in a dynamic menu item to indicate that it has a submenu. |
DynamicTopSeparatorImageUrl
| An optional image displayed at the top of a dynamic menu item to separate it from other menu items. |
ScrollDownImageUrl
| The image displayed at the bottom of a menu item to indicate that the user can scroll down to view additional menu items. |
ScrollUpImageUrl
| The image displayed at the top of a menu item to indicate that the user can scroll up to view additional menu items. |
StaticBottomSeparatorImageUrl
| An optional image displayed at the bottom of a static menu item to separate it from other menu items. |
StaticPopOutImageUrl
| An optional image displayed in a static menu item to indicate that it has a submenu. |
StaticTopSeparatorImageUrl
| An optional image displayed at the top of a static menu item to separate it from other menu items. |
For complete control of the user interface (UI), you can define your own custom templates for the Menu control using the following template properties. Template property | Description |
|---|
DynamicItemTemplate
| The template that contains the custom content to render for a dynamic menu item. |
StaticItemTemplate
| The template that contains the custom content to render for a static menu item. |
You can control the vertical and horizontal position of a dynamic menu relative to its parent menu item by setting the DynamicVerticalOffset and DynamicHorizontalOffset properties, respectively. To control the indentation of the static submenu items within a static menu, use the StaticSubMenuIndent property. EventsThe Menu control provides several events that you can program against. This allows you to run a custom routine whenever an event occurs. The following table lists the supported events. Event | Description |
|---|
MenuItemClick
| Occurs when a menu item is clicked. This event is commonly used to synchronize a Menu control with another control on the page. |
MenuItemDataBound
| Occurs when a menu item is bound to data. This event is commonly used to modify a menu item before it is rendered in a Menu control. |
AccessibilityDeclarative Syntax
<asp:Menu
AccessKey="string"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
Inset|Outset"
BorderWidth="size"
CssClass="string"
DataSource="string"
DataSourceID="string"
DisappearAfter="integer"
DynamicBottomSeparatorImageUrl="uri"
DynamicEnableDefaultPopOutImage="True|False"
DynamicHorizontalOffset="integer"
DynamicItemFormatString="string"
DynamicPopOutImageTextFormatString="string"
DynamicPopOutImageUrl="uri"
DynamicTopSeparatorImageUrl="uri"
DynamicVerticalOffset="integer"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
ID="string"
ItemWrap="True|False"
MaximumDynamicDisplayLevels="integer"
OnDataBinding="DataBinding event handler"
OnDataBound="DataBound event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnMenuItemClick="MenuItemClick event handler"
OnMenuItemDataBound="MenuItemDataBound event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
Orientation="Horizontal|Vertical"
PathSeparator="string"
runat="server"
ScrollDownImageUrl="uri"
ScrollDownText="string"
ScrollUpImageUrl="uri"
ScrollUpText="string"
SkinID="string"
SkipLinkText="string"
StaticBottomSeparatorImageUrl="uri"
StaticDisplayLevels="integer"
StaticEnableDefaultPopOutImage="True|False"
StaticItemFormatString="string"
StaticPopOutImageTextFormatString="string"
StaticPopOutImageUrl="uri"
StaticSubMenuIndent="size"
StaticTopSeparatorImageUrl="uri"
Style="string"
TabIndex="integer"
Target="string"
ToolTip="string"
Visible="True|False"
Width="size"
>
<DataBindings>
<asp:MenuItemBinding
DataMember="string"
Depth="integer"
Enabled="True|False"
EnabledField="string"
FormatString="string"
ImageUrl="uri"
ImageUrlField="string"
NavigateUrl="uri"
NavigateUrlField="string"
PopOutImageUrl="uri"
PopOutImageUrlField="string"
Selectable="True|False"
SelectableField="string"
SeparatorImageUrl="uri"
SeparatorImageUrlField="string"
Target="string"
TargetField="string"
Text="string"
TextField="string"
ToolTip="string"
ToolTipField="string"
Value="string"
ValueField="string"
/>
</DataBindings>
<DynamicHoverStyle />
<DynamicItemTemplate>
<!-- child controls -->
</DynamicItemTemplate>
<DynamicMenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<DynamicMenuStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<DynamicSelectedStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<Items />
<LevelMenuItemStyles>
<asp:MenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|
Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</LevelMenuItemStyles>
<LevelSelectedStyles>
<asp:MenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|
Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</LevelSelectedStyles>
<LevelSubMenuStyles>
<asp:SubMenuStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|
Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</LevelSubMenuStyles>
<StaticHoverStyle />
<StaticItemTemplate>
<!-- child controls -->
</StaticItemTemplate>
<StaticMenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<StaticMenuStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<StaticSelectedStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</asp:Menu>

Examples
A Visual Studio Web site project with source code is available to accompany this topic: Download. The following code example demonstrates how to create a Menu control with static menu items using declarative syntax.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu Declarative Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu Declarative Example</h3>
<!-- Use declarative syntax to create the -->
<!-- menu structure. Submenu items are -->
<!-- created by nesting them in parent menu -->
<!-- items. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Home"
tooltip="Home">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Movies"
tooltip="Movies">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu Declarative Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu Declarative Example</h3>
<!-- Use declarative syntax to create the -->
<!-- menu structure. Submenu items are -->
<!-- created by nesting them in parent menu -->
<!-- items. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Home"
tooltip="Home">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Movies"
tooltip="Movies">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
The following code example demonstrates how to bind the Menu control to a SiteMapDataSource control. For this example to work correctly, you must copy the sample site map data below to a file named Web.sitemap.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu DataBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu DataBinding Example</h3>
<!-- Bind the Menu control to a SiteMapDataSource control. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
datasourceid="MenuSource"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
</asp:menu>
<asp:SiteMapDataSource id="MenuSource"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu DataBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu DataBinding Example</h3>
<!-- Bind the Menu control to a SiteMapDataSource control. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
datasourceid="MenuSource"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
</asp:menu>
<asp:SiteMapDataSource id="MenuSource"
runat="server"/>
</form>
</body>
</html>
The following is sample site map data for the previous example.
<siteMap>
<siteMapNode url="~\Home.aspx"
title="Home"
description="Home">
<siteMapNode url="~\Music.aspx"
title="Music"
description="Music">
<siteMapNode url="~\Classical.aspx"
title="Classical"
description="Classical"/>
<siteMapNode url="~\Rock.aspx"
title="Rock"
description="Rock"/>
<siteMapNode url="~\Jazz.aspx"
title="Jazz"
description="Jazz"/>
</siteMapNode>
<siteMapNode url="~\Movies.aspx"
title="Movies"
description="Movies">
<siteMapNode url="~\Action.aspx"
title="Action"
description="Action"/>
<siteMapNode url="~\Drama.aspx"
title="Drama"
description="Drama"/>
<siteMapNode url="~\Musical.aspx"
title="Musical"
description="Musical"/>
</siteMapNode>
</siteMapNode>
</siteMap>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework Menu, classe Affiche un menu dans une page Web ASP.NET.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
<ControlValuePropertyAttribute("SelectedValue")> _
Public Class Menu _
Inherits HierarchicalDataBoundControl _
Implements IPostBackEventHandler, INamingContainer
[ControlValuePropertyAttribute("SelectedValue")]
public class Menu : HierarchicalDataBoundControl, IPostBackEventHandler, INamingContainer
[ControlValuePropertyAttribute(L"SelectedValue")]
public ref class Menu : public HierarchicalDataBoundControl,
IPostBackEventHandler, INamingContainer
[<ControlValuePropertyAttribute("SelectedValue")>]
type Menu =
class
inherit HierarchicalDataBoundControl
interface IPostBackEventHandler
interface INamingContainer
end
Le type Menu expose les membres suivants.

Constructeurs
|
| Nom | Description |
|---|
.gif) | Menu | Initialise une nouvelle instance de la classe Menu. | Début

Méthodes
|
| Nom | Description |
|---|
.gif) | AddAttributesToRender | Ajoute des attributs et des styles HTML qui doivent être rendus à l'objet HtmlTextWriter spécifié. (Substitue WebControl..::.AddAttributesToRender(HtmlTextWriter).) | .gif) | AddedControl | Appelée après l'ajout d'un contrôle enfant à la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | AddParsedSubObject | Avertit le contrôle serveur qu'un élément XML ou HTML a été analysé et l'ajoute à l'objet ControlCollection du contrôle serveur. (Hérité de Control.) | .gif) | ApplyStyle | Copie tous les éléments non vides du style spécifié vers le contrôle Web, en remplaçant les éléments de style existants du contrôle. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | ApplyStyleSheetSkin | Applique les propriétés de style définies dans la feuille de style de la page au contrôle. (Hérité de Control.) | .gif) | BuildProfileTree | Infrastructure. Collecte des informations sur le contrôle serveur et les livre à la propriété Trace à afficher lorsque le traçage est activé pour la page. (Hérité de Control.) | .gif) | ClearCachedClientID | Infrastructure. Affecte à la valeur ClientID mise en cache la valeur nullNothingnullptrune référence null (Nothing en Visual Basic). (Hérité de Control.) | .gif) | ClearChildControlState | Supprime les informations sur l'état du contrôle des contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildState | Supprime les informations sur l'état d'affichage et sur l'état du contrôle de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildViewState | Supprime les informations d'état d'affichage de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Affecte la valeur Inherit à la propriété ClientIDMode de l'instance de contrôle actuelle et de tous contrôles enfants. (Hérité de Control.) | .gif) | ConfirmInitState | Définit l'état initialisé du contrôle lié aux données. (Hérité de BaseDataBoundControl.) | .gif) | CopyBaseAttributes | Copie les propriétés non encapsulées par l'objet Style du contrôle serveur Web spécifié vers le contrôle serveur Web à partir duquel cette méthode est appelée. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | CreateChildControls | Crée les contrôles enfants d'un contrôle Menu. (Substitue Control..::.CreateChildControls()()().) | .gif) | CreateControlCollection | Crée un nouvel objet ControlCollection pour contenir les contrôles enfants (littéraux et serveur) du contrôle serveur. (Hérité de Control.) | .gif) | CreateControlStyle | Crée l'objet de style qui est utilisé de manière interne par la classe WebControl pour implémenter toutes les propriétés associées au style. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | DataBind()()() | Lie la source de données au contrôle Menu. Cette méthode ne peut pas être héritée. (Substitue BaseDataBoundControl..::.DataBind()()().) | .gif) | DataBind(Boolean) | Lie une source de données au contrôle serveur appelé et tous ses contrôles enfants avec une option pour déclencher l'événement DataBinding. (Hérité de Control.) | .gif) | DataBindChildren | Lie une source de données aux contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | Dispose | Permet à un contrôle serveur d'effectuer le nettoyage final avant qu'il soit libéré de la mémoire. (Hérité de Control.) | .gif) | EnsureChildControls | Détermine si le contrôle serveur contient des contrôles enfants. S'il ne contient pas de contrôles enfants, il en crée. (Hérité de Control.) | .gif) | EnsureDataBound | Vérifie que le contrôle de menu requiert la liaison de données et qu'un contrôle de source de données valide est spécifié avant d'appeler la méthode DataBind. (Substitue BaseDataBoundControl..::.EnsureDataBound()()().) | .gif) | EnsureID | Crée un identificateur pour les contrôles auxquels aucun identificateur n'est assigné. (Hérité de Control.) | .gif) | Equals(Object) | Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.) | .gif) | Finalize | Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.) | .gif) | FindControl(String) | Recherche un contrôle serveur possédant le paramètre id spécifié dans le conteneur d'attribution de noms actuel. (Hérité de Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Recherche le conteneur d'attribution de noms actuel d'un contrôle serveur avec l'id spécifié et un entier, spécifié dans le paramètre pathOffset, qui facilite la recherche. Vous ne devez pas substituer cette version de la méthode FindControl. (Hérité de Control.) | .gif) | FindItem | Récupère l'élément de menu au chemin de valeur spécifié. | .gif) | Focus | Affecte le focus d'entrée à un contrôle. (Hérité de Control.) | .gif) | GetData | Récupère un objet HierarchicalDataSourceView que le contrôle lié aux données utilise pour exécuter des opérations de données. (Hérité de HierarchicalDataBoundControl.) | .gif) | GetDataSource | Récupère le IHierarchicalDataSource auquel le contrôle lié aux données est associé, le cas échéant. (Hérité de HierarchicalDataBoundControl.) | .gif) | GetDesignModeState | Récupère l'état au moment du design du contrôle Menu. (Substitue Control..::.GetDesignModeState()()().) | .gif) | GetHashCode | Sert de fonction de hachage pour un type particulier. (Hérité de Object.) | .gif) | GetRouteUrl(Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetType | Obtient le Type de l'instance actuelle. (Hérité de Object.) | .gif) | GetUniqueIDRelativeTo | Retourne la partie préfixée de la propriété UniqueID du contrôle spécifié. (Hérité de Control.) | .gif) | HasControls | Détermine si le contrôle serveur contient des contrôles enfants. (Hérité de Control.) | .gif) | HasEvents | Retourne une valeur indiquant si des événements sont inscrits pour le contrôle ou des contrôles enfants. (Hérité de Control.) | .gif) | IsLiteralContent | Infrastructure. Détermine si le contrôle serveur ne détient qu'un contenu littéral. (Hérité de Control.) | .gif) | LoadControlState | Charge l'état des propriétés du contrôle Menu qui doivent être persistants. (Substitue Control..::.LoadControlState(Object).) | .gif) | LoadViewState | Charge l'état d'affichage enregistré précédemment du contrôle Menu. (Substitue WebControl..::.LoadViewState(Object).) | .gif) | MapPathSecure | Récupère le chemin d'accès physique auquel un chemin d'accès virtuel, absolu ou relatif, correspond. (Hérité de Control.) | .gif) | MarkAsDataBound | Définit l'état du contrôle dans l'état d'affichage comme lié avec succès aux données. (Hérité de HierarchicalDataBoundControl.) | .gif) | MemberwiseClone | Crée une copie superficielle de l'objet Object actif. (Hérité de Object.) | .gif) | MergeStyle | Copie tous les éléments non vides du style spécifié vers le contrôle Web, mais ne remplace aucun élément de style existant du contrôle. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | OnBubbleEvent | Infrastructure. Détermine si l'événement du contrôle Menu est passé dans la hiérarchie des contrôles serveur de l'interface utilisateur de la page. (Substitue Control..::.OnBubbleEvent(Object, EventArgs).) | .gif) | OnDataBinding | Déclenche l'événement DataBinding. (Substitue Control..::.OnDataBinding(EventArgs).) | .gif) | OnDataBound | Déclenche l'événement DataBound. (Hérité de BaseDataBoundControl.) | .gif) | OnDataPropertyChanged | Appelé lorsque l'une des propriétés d'identification de la source de données de base est modifiée, pour rétablir la liaison du contrôle lié aux données à ses données. (Hérité de HierarchicalDataBoundControl.) | .gif) | OnDataSourceChanged | Appelé lorsque l'instance de IHierarchicalDataSource avec laquelle fonctionne le contrôle lié aux données déclenche l'événement DataSourceChanged. (Hérité de HierarchicalDataBoundControl.) | .gif) | OnInit | Infrastructure. Déclenche l'événement Init. (Substitue BaseDataBoundControl..::.OnInit(EventArgs).) | .gif) | OnLoad | Gère l'événement Load. (Hérité de HierarchicalDataBoundControl.) | .gif) | OnMenuItemClick | Déclenche l'événement MenuItemClick. | .gif) | OnMenuItemDataBound | Déclenche l'événement MenuItemDataBound. | .gif) | OnPagePreLoad | Définit l'état initialisé du contrôle lié aux données avant que le contrôle ne soit chargé. (Hérité de HierarchicalDataBoundControl.) | .gif) | OnPreRender | Infrastructure. Déclenche l'événement PreRender. (Substitue BaseDataBoundControl..::.OnPreRender(EventArgs).) | .gif) | OnUnload | Déclenche l'événement Unload. (Hérité de Control.) | .gif) | OpenFile | Obtient un Stream utilisé pour lire un fichier. (Hérité de Control.) | .gif) | PerformDataBinding | Infrastructure. Lie les éléments de la source de données aux éléments de menu dans le contrôle Menu. (Substitue HierarchicalDataBoundControl..::.PerformDataBinding()()().) | .gif) | PerformSelect | Récupère les données de la source de données associée. (Hérité de HierarchicalDataBoundControl.) | .gif) | RaiseBubbleEvent | Assigne les sources éventuelles de l'événement et ses informations au parent du contrôle. (Hérité de Control.) | .gif) | RaisePostBackEvent | Traite un événement déclenché lorsqu'un formulaire est publié sur le serveur. | .gif) | RemovedControl | Appelée après la suppression d'un contrôle enfant dans la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | Render | Infrastructure. Génère le rendu du contrôle de menu sur le navigateur du client. (Substitue WebControl..::.Render(HtmlTextWriter).) | .gif) | RenderBeginTag | Ajoute des attributs de balise et écrit le balisage de la balise d'ouverture du contrôle dans le flux de sortie émis vers le navigateur ou l'appareil. (Substitue WebControl..::.RenderBeginTag(HtmlTextWriter).) | .gif) | RenderChildren | Renvoie le contenu des enfants d'un contrôle serveur dans un objet HtmlTextWriter fourni, qui écrit le contenu à rendre sur le client. (Hérité de Control.) | .gif) | RenderContents | Infrastructure. Ce membre se substitue à RenderContents. (Substitue WebControl..::.RenderContents(HtmlTextWriter).) | .gif) | RenderControl(HtmlTextWriter) | Renvoie le contenu du contrôle serveur dans un objet HtmlTextWriter fourni et stocke des informations de traçage au sujet du contrôle si le traçage est activé. (Hérité de Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Génère le contenu du contrôle serveur dans un objet HtmlTextWriter à l'aide d'un objet ControlAdapter fourni. (Hérité de Control.) | .gif) | RenderEndTag | Effectue le balisage final et écrit la balise de fermeture HTML du contrôle dans le flux de sortie émis vers le navigateur ou l'appareil. (Substitue WebControl..::.RenderEndTag(HtmlTextWriter).) | .gif) | ResolveAdapter | Obtient l'adaptateur de contrôles responsable du rendu du contrôle spécifié. (Hérité de Control.) | .gif) | ResolveClientUrl | Obtient une URL qui peut être utilisée par le navigateur. (Hérité de Control.) | .gif) | ResolveUrl | Convertit une URL en une URL que le client soit en mesure d'utiliser. (Hérité de Control.) | .gif) | SaveControlState | Infrastructure. Enregistre l'état des propriétés du contrôle Menu qui doivent être persistants. (Substitue Control..::.SaveControlState()()().) | .gif) | SaveViewState | Enregistre l'état du contrôle Menu. (Substitue WebControl..::.SaveViewState()()().) | .gif) | SetDesignModeState | Définit les données au moment du design pour le contrôle Menu. (Substitue Control..::.SetDesignModeState(IDictionary).) | .gif) | SetItemDataBound | Définit la propriété DataBound de l'objet MenuItem spécifié avec la valeur spécifiée. | .gif) | SetItemDataItem | Définit la propriété DataItem de l'objet MenuItem spécifié avec la valeur spécifiée. | .gif) | SetItemDataPath | Définit la propriété DataPath de l'objet MenuItem spécifié avec la valeur spécifiée. | .gif) | SetRenderMethodDelegate | Infrastructure. Assigne un délégué de gestionnaires d'événements pour générer le rendu du contrôle serveur et de son contenu dans son contrôle parent. (Hérité de Control.) | .gif) | ToString | Retourne une chaîne qui représente l'objet actuel. (Hérité de Object.) | .gif) | TrackViewState | Suit les modifications d'état d'affichage du contrôle Menu afin qu'elles puissent être stockées dans l'objet StateBag du contrôle. Cet objet est accessible à l'aide de la propriété ViewState. (Substitue WebControl..::.TrackViewState()()().) | .gif) | ValidateDataSource | Vérifie que l'objet auquel un contrôle lié aux données se lie est un objet avec qui il peut fonctionner. (Hérité de HierarchicalDataBoundControl.) | Début

Méthodes d'extension

Champs

Implémentations d'interface explicite
|
| Nom | Description |
|---|
.gif) .gif) | IAttributeAccessor..::.GetAttribute | Infrastructure. Obtient un attribut du contrôle Web avec le nom spécifié. (Hérité de WebControl.) | .gif) .gif) | IAttributeAccessor..::.SetAttribute | Affecte au nom et à la valeur spécifiés un attribut du contrôle Web. (Hérité de WebControl.) | .gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | Pour obtenir une description de ce membre, consultez IControlBuilderAccessor..::.ControlBuilder. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.GetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetOwnerControl. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.UserData. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.DataBindings. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.HasDataBindings. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.Expressions. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.HasExpressions. (Hérité de Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | Pour obtenir une description de ce membre, consultez IParserAccessor..::.AddParsedSubObject. (Hérité de Control.) | .gif) .gif) | IPostBackEventHandler..::.RaisePostBackEvent | Infrastructure. Traite un événement déclenché lorsqu'un formulaire est publié sur le serveur. | Début

Notes
Dans cette rubrique : IntroductionLe contrôle Menu permet d'afficher un menu dans une page Web ASP.NET et est souvent associé à un contrôle SiteMapDataSource pour parcourir un site Web. Le contrôle Menu prend en charge les fonctionnalités suivantes : Liaison de données qui permet aux éléments de menu du contrôle d'être liés aux sources de données hiérarchiques. Navigation de site via l'intégration avec le contrôle SiteMapDataSource. Accès par programme au modèle objet Menu pour créer des menus de manière dynamique, remplir les éléments de menu, définir les propriétés, etc. Apparence personnalisable grâce aux thèmes, images, styles et modèles définis par l'utilisateur.
Lorsque l'utilisateur clique sur un élément de menu, le contrôle Menu peut naviguer vers une page Web liée ou simplement effectuer une publication sur le serveur. Si la propriété NavigateUrl d'un élément de menu est définie, le contrôle Menu navigue vers la page liée ; sinon, il publie la page sur le serveur pour traitement. Par défaut, une page liée s'affiche dans la même fenêtre ou frame que le contrôle Menu. Pour afficher le contenu lié dans une fenêtre ou frame différent, utilisez la propriété Target du contrôle Menu. Remarque |
|---|
La propriété Target affecte chaque élément de menu du contrôle. Pour spécifier une fenêtre ou frame d'un élément de menu, définissez directement la propriété Target de l'objet MenuItem. |
Le contrôle Menu affiche deux types de menus : un menu statique et un menu dynamique. Le menu statique s'affiche toujours dans un contrôle Menu. Par défaut, les éléments de menu au niveau racine (niveau 0) s'affichent dans le menu statique. Vous pouvez afficher des niveaux de menu supplémentaires (sous-menus statiques) dans le menu statique en définissant la propriété StaticDisplayLevels. Les éléments de menu (le cas échéant) avec un niveau supérieur à la valeur spécifiée par la propriété StaticDisplayLevels s'affichent dans un menu dynamique. Un menu dynamique n'apparaît que lorsque l'utilisateur positionne le pointeur de la souris sur l'élément de menu parent qui contient un sous-menu dynamique. Les menus dynamiques disparaissent automatiquement au bout d'un certain temps. Utilisez la propriété DisappearAfter pour spécifier la durée. Remarque |
|---|
Un menu dynamique disparaît également lorsque l'utilisateur clique en dehors du menu. |
Vous pouvez également limiter le nombre de niveaux affiché dans un menu dynamique en définissant la propriété MaximumDynamicDisplayLevels. Les niveaux de menu supérieurs à la valeur spécifiée sont ignorés. Éléments de menuUn contrôle Menu est composé d'une arborescence d'éléments de menu représentée par les objets MenuItem. Les éléments de menu du niveau supérieur (niveau 0) sont appelés éléments de menu racine. Un élément de menu ayant un élément de menu parent est appelé élément de menu enfant. Tous les éléments de menu racine sont stockés dans la collection Items. Les éléments de menu enfants sont stockés dans une collection ChildItems d'un élément de menu parent. Chaque élément de menu a un Text et une propriété Value. La valeur de la propriété Text s'affiche dans le contrôle Menu, tandis que la propriété Value permet de stocker toutes les données supplémentaires relatives à l'élément de menu, telles que les données passées à l'événement de publication associé à l'élément de menu. Lorsque vous cliquez dessus, un élément de menu peut naviguer vers une autre page Web indiquée par la propriété NavigateUrl. Remarque |
|---|
Si la propriété NavigateUrl d'un élément de menu n'est pas définie, le contrôle Menu soumet simplement la page au serveur pour traitement lorsque vous cliquez sur l'élément de menu. |
Vous pouvez aussi afficher éventuellement une image dans un élément de menu en définissant la propriété ImageUrl. Pour plus d'informations sur les éléments de menu, consultez MenuItem. Données statiquesLe modèle de données le plus simple du contrôle Menu correspond aux éléments de menu statiques. Pour afficher les éléments de menu statiques à l'aide d'une syntaxe déclarative, commencez par imbriquer les balises <Items> d'ouverture et de fermeture entre les balises d'ouverture et de fermeture du contrôle Menu. Ensuite, créez la structure de menu en imbriquant les éléments <asp:MenuItem> entre les balises <Items> d'ouverture et de fermeture. Chaque élément <asp:MenuItem> représente un élément de menu du contrôle et correspond à un objet MenuItem. Vous pouvez définir les propriétés de chaque élément de menu en définissant les attributs de son élément <asp:MenuItem>. Pour créer des éléments de sous-menu, imbriquez des éléments <asp:MenuItem> supplémentaires entre les balises <asp:MenuItem> d'ouverture et de fermeture de l'élément de menu parent. Liaison de donnéesLe contrôle Menu peut utiliser n'importe quel contrôle de source de données hiérarchique, par exemple un contrôle XmlDataSource ou un contrôle SiteMapDataSource. Pour effectuer une liaison à un contrôle de source de données hiérarchique, affectez à la propriété DataSourceID du contrôle Menu la valeur ID du contrôle de source de données. Le contrôle Menu se lie automatiquement au contrôle de source de données spécifié. Il s'agit de la méthode recommandée de liaison aux données. Lorsque vous effectuez une liaison à une source de données où chaque élément de données contient plusieurs propriétés (tel qu'un élément XML avec plusieurs attributs), un élément de menu affiche la valeur retournée par la méthode ToString de l'élément de données par défaut. Dans le cas d'un élément XML, l'élément de menu affiche le nom de l'élément, lequel affiche la structure sous-jacente de l'arborescence de menu, mais qui n'est pas très utile par ailleurs. Vous pouvez lier un élément de menu à une propriété d'élément de données spécifique en utilisant la collection DataBindings pour spécifier des liaisons d'éléments de menu. La collection DataBindings contient des objets MenuItemBinding qui définissent la relation entre un élément de données et l'élément de menu auquel il est lié. Vous pouvez spécifier les critères de liaison et la propriété de l'élément de données à afficher dans le nœud. Pour plus d'informations sur les liaisons d'éléments de menu, consultez MenuItemBinding. Vous ne pouvez pas créer de nœud vide dans un contrôle Menu en affectant aux propriétés Text ou TextField la valeur d'une chaîne vide (""). L'affectation de la valeur d'une chaîne vide à ces propriétés équivaut à ne pas définir les propriétés. Dans ce cas, le contrôle Menu crée une liaison par défaut à l'aide de la propriété DataSource. Pour plus d'informations, consultez Liaison à des bases de données. Personnalisation de l'interface utilisateurIl existe plusieurs manières de personnaliser l'apparence du contrôle Menu. En premier lieu, vous pouvez spécifier si le contrôle Menu est rendu horizontalement ou verticalement en définissant la propriété Orientation. Vous pouvez également spécifier un style différent (par exemple une taille et une couleur de police) pour chacun des types d'éléments de menu. Si vous utilisez des feuilles de style en cascade (CSS, Cascading Style Sheets) pour personnaliser l'apparence du contrôle, utilisez des styles intralignes ou un fichier CSS distinct, mais pas les deux en même temps. L'utilisation conjointe des styles intralignes et d'un fichier CSS distinct peut entraîner des résultats inattendus. Pour plus d'informations sur l'utilisation des feuilles de style avec des contrôles, consultez Contrôles serveur Web ASP.NET et styles CSS. Le tableau suivant répertorie les styles d'élément de menu disponibles. Propriété de style d'élément de menu | Description |
|---|
DynamicHoverStyle
| Paramètres de style d'un élément de menu dynamique lorsque le pointeur de la souris est positionné sur lui. |
DynamicMenuItemStyle
| Paramètres de style d'un élément de menu dynamique. |
DynamicMenuStyle
| Paramètres de style d'un menu dynamique. |
DynamicSelectedStyle
| Paramètres de style de l'élément de menu dynamique actuellement sélectionné. |
StaticHoverStyle
| Paramètres de style d'un élément de menu statique lorsque le pointeur de la souris est positionné sur lui. |
StaticMenuItemStyle
| Paramètres de style d'un élément de menu statique. |
StaticMenuStyle
| Paramètres de style d'un menu statique. |
StaticSelectedStyle
| Paramètres de style de l'élément de menu statique actuellement sélectionné. |
Au lieu de définir les propriétés de style, vous pouvez spécifier les styles appliqués aux éléments de menu en fonction de leur niveau à l'aide des collections de styles suivantes. Le premier style de la collection correspond au style des éléments de menu au premier niveau de profondeur de l'arborescence du menu. Le deuxième style de la collection correspond au style des éléments de menu au deuxième niveau de profondeur de l'arborescence du menu, et ainsi de suite. Ce mécanisme est le plus souvent utilisé pour générer des menus de navigation de style table des matières où les éléments de menu, à une certaine profondeur, doivent avoir la même apparence, qu'ils aient ou non des sous-menus. Remarque |
|---|
Si vous utilisez l'une des collections de styles de niveau répertoriées dans le tableau précédent pour définir le style du contrôle Menu, ces paramètres de style substituent les propriétés de style de l'élément de menu. |
La personnalisation des images affichées dans le contrôle Menu est une autre manière de modifier l'apparence du contrôle. Vous pouvez spécifier votre propre image personnalisée pour les différentes parties du contrôle en définissant les propriétés affichées dans le tableau suivant. Propriété d'image | Description |
|---|
DynamicBottomSeparatorImageUrl
| Image facultative affichée en bas d'un élément de menu dynamique pour le séparer d'autres éléments de menu. |
DynamicPopOutImageUrl
| Image facultative affichée dans un élément de menu dynamique pour indiquer qu'il a un sous-menu. |
DynamicTopSeparatorImageUrl
| Image facultative affichée en haut d'un élément de menu dynamique pour le séparer d'autres éléments de menu. |
ScrollDownImageUrl
| Image affichée en bas d'un élément de menu pour indiquer que l'utilisateur peut faire défiler les éléments vers le bas pour afficher des éléments de menu supplémentaires. |
ScrollUpImageUrl
| Image affichée en haut d'un élément de menu pour indiquer que l'utilisateur peut faire défiler les éléments vers le haut pour afficher des éléments de menu supplémentaires. |
StaticBottomSeparatorImageUrl
| Image facultative affichée en bas d'un élément de menu statique pour le séparer d'autres éléments de menu. |
StaticPopOutImageUrl
| Image facultative affichée dans un élément de menu statique pour indiquer qu'il a un sous-menu. |
StaticTopSeparatorImageUrl
| Image facultative affichée en haut d'un élément de menu statique pour le séparer d'autres éléments de menu. |
Pour un contrôle complet de l'interface utilisateur, vous pouvez définir vos propres modèles personnalisés pour le contrôle Menu à l'aide des propriétés de modèle suivantes. Propriété du modèle | Description |
|---|
DynamicItemTemplate
| Modèle qui contient le contenu personnalisé à rendre pour un élément de menu dynamique. |
StaticItemTemplate
| Modèle qui contient le contenu personnalisé à rendre pour un élément de menu statique. |
Vous pouvez contrôler la position verticale et horizontale d'un menu dynamique relatif à son élément de menu parent en définissant respectivement les propriétés DynamicVerticalOffset et DynamicHorizontalOffset. Pour contrôler la mise en retrait des éléments de sous-menu statiques d'un menu statique, utilisez la propriété StaticSubMenuIndent. ÉvénementsLe contrôle Menu fournit plusieurs événements que vous pouvez programmer. Cela vous permet d'exécuter une routine personnalisée lorsqu'un événement se produit. Le tableau suivant répertorie les événements pris en charge. Événement | Description |
|---|
MenuItemClick
| Se produit lorsqu'un utilisateur clique sur un élément de menu. Cet événement est utilisé couramment pour synchroniser un contrôle Menu avec un autre contrôle de la page. |
MenuItemDataBound
| Se produit lorsqu'un élément de menu est lié à des données. Cet événement est utilisé couramment pour modifier un élément de menu avant qu'il soit rendu dans un contrôle Menu. |
AccessibilitéSyntaxe déclarative
<asp:Menu
AccessKey="string"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
Inset|Outset"
BorderWidth="size"
CssClass="string"
DataSource="string"
DataSourceID="string"
DisappearAfter="integer"
DynamicBottomSeparatorImageUrl="uri"
DynamicEnableDefaultPopOutImage="True|False"
DynamicHorizontalOffset="integer"
DynamicItemFormatString="string"
DynamicPopOutImageTextFormatString="string"
DynamicPopOutImageUrl="uri"
DynamicTopSeparatorImageUrl="uri"
DynamicVerticalOffset="integer"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
ID="string"
ItemWrap="True|False"
MaximumDynamicDisplayLevels="integer"
OnDataBinding="DataBinding event handler"
OnDataBound="DataBound event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnMenuItemClick="MenuItemClick event handler"
OnMenuItemDataBound="MenuItemDataBound event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
Orientation="Horizontal|Vertical"
PathSeparator="string"
runat="server"
ScrollDownImageUrl="uri"
ScrollDownText="string"
ScrollUpImageUrl="uri"
ScrollUpText="string"
SkinID="string"
SkipLinkText="string"
StaticBottomSeparatorImageUrl="uri"
StaticDisplayLevels="integer"
StaticEnableDefaultPopOutImage="True|False"
StaticItemFormatString="string"
StaticPopOutImageTextFormatString="string"
StaticPopOutImageUrl="uri"
StaticSubMenuIndent="size"
StaticTopSeparatorImageUrl="uri"
Style="string"
TabIndex="integer"
Target="string"
ToolTip="string"
Visible="True|False"
Width="size"
>
<DataBindings>
<asp:MenuItemBinding
DataMember="string"
Depth="integer"
Enabled="True|False"
EnabledField="string"
FormatString="string"
ImageUrl="uri"
ImageUrlField="string"
NavigateUrl="uri"
NavigateUrlField="string"
PopOutImageUrl="uri"
PopOutImageUrlField="string"
Selectable="True|False"
SelectableField="string"
SeparatorImageUrl="uri"
SeparatorImageUrlField="string"
Target="string"
TargetField="string"
Text="string"
TextField="string"
ToolTip="string"
ToolTipField="string"
Value="string"
ValueField="string"
/>
</DataBindings>
<DynamicHoverStyle />
<DynamicItemTemplate>
<!-- child controls -->
</DynamicItemTemplate>
<DynamicMenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<DynamicMenuStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<DynamicSelectedStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<Items />
<LevelMenuItemStyles>
<asp:MenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|
Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</LevelMenuItemStyles>
<LevelSelectedStyles>
<asp:MenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|
Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</LevelSelectedStyles>
<LevelSubMenuStyles>
<asp:SubMenuStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|
Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</LevelSubMenuStyles>
<StaticHoverStyle />
<StaticItemTemplate>
<!-- child controls -->
</StaticItemTemplate>
<StaticMenuItemStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<StaticMenuStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<StaticSelectedStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ItemSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</asp:Menu>

Exemples
Un projet de site Web Visual Studio contenant du code source est disponible pour accompagner cette rubrique : Download. L'exemple de code suivant montre comment créer un contrôle Menu avec les éléments de menu statiques à l'aide d'une syntaxe déclarative.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu Declarative Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu Declarative Example</h3>
<!-- Use declarative syntax to create the -->
<!-- menu structure. Submenu items are -->
<!-- created by nesting them in parent menu -->
<!-- items. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Home"
tooltip="Home">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Movies"
tooltip="Movies">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu Declarative Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu Declarative Example</h3>
<!-- Use declarative syntax to create the -->
<!-- menu structure. Submenu items are -->
<!-- created by nesting them in parent menu -->
<!-- items. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Home"
tooltip="Home">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Movies"
tooltip="Movies">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
L'exemple de code suivant montre comment lier le contrôle Menu à un contrôle SiteMapDataSource. Pour que cet exemple fonctionne, vous devez copier les données du plan de site ci-dessous dans un fichier nommé Web.sitemap.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu DataBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu DataBinding Example</h3>
<!-- Bind the Menu control to a SiteMapDataSource control. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
datasourceid="MenuSource"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
</asp:menu>
<asp:SiteMapDataSource id="MenuSource"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- For the hover styles of the Menu control to -->
<!-- work correctly, you must include this head -->
<!-- element. -->
<head runat="server">
<title>Menu DataBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu DataBinding Example</h3>
<!-- Bind the Menu control to a SiteMapDataSource control. -->
<asp:menu id="NavigationMenu"
disappearafter="2000"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
font-names="Arial"
target="_blank"
datasourceid="MenuSource"
runat="server">
<staticmenuitemstyle backcolor="LightSteelBlue"
forecolor="Black"/>
<statichoverstyle backcolor="LightSkyBlue"/>
<dynamicmenuitemstyle backcolor="Black"
forecolor="Silver"/>
<dynamichoverstyle backcolor="LightSkyBlue"
forecolor="Black"/>
</asp:menu>
<asp:SiteMapDataSource id="MenuSource"
runat="server"/>
</form>
</body>
</html>
Ceci est un exemple de données de plan de site de l'exemple précédent.
<siteMap>
<siteMapNode url="~\Home.aspx"
title="Home"
description="Home">
<siteMapNode url="~\Music.aspx"
title="Music"
description="Music">
<siteMapNode url="~\Classical.aspx"
title="Classical"
description="Classical"/>
<siteMapNode url="~\Rock.aspx"
title="Rock"
description="Rock"/>
<siteMapNode url="~\Jazz.aspx"
title="Jazz"
description="Jazz"/>
</siteMapNode>
<siteMapNode url="~\Movies.aspx"
title="Movies"
description="Movies">
<siteMapNode url="~\Action.aspx"
title="Action"
description="Action"/>
<siteMapNode url="~\Drama.aspx"
title="Drama"
description="Drama"/>
<siteMapNode url="~\Musical.aspx"
title="Musical"
description="Musical"/>
</siteMapNode>
</siteMapNode>
</siteMap>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
|