Suggérer une traduction
 
Suggestions d'autres utilisateurs :

progress indicator
Aucune autre suggestion.
Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 4
Espaces de noms System.Web
System.Web.UI.WebControls
MenuItemBinding, classe
Réduire tout/Développer tout Réduire tout
Affichage du contenu :  côte à côteAffichage du contenu : côte à côte
.NET Framework Class Library
MenuItemBinding Class

Defines the relationship between a data item and the menu item it is binding to in a Menu control. This class cannot be inherited.

System..::.Object
  System.Web.UI.WebControls..::.MenuItemBinding

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public NotInheritable Class MenuItemBinding _
    Implements IStateManager, ICloneable, IDataSourceViewSchemaAccessor
C#
public sealed class MenuItemBinding : IStateManager, 
    ICloneable, IDataSourceViewSchemaAccessor
Visual C++
public ref class MenuItemBinding sealed : IStateManager, 
    ICloneable, IDataSourceViewSchemaAccessor
F#
[<Sealed>]
type MenuItemBinding =  
    class
        interface IStateManager
        interface ICloneable
        interface IDataSourceViewSchemaAccessor
    end

The MenuItemBinding type exposes the following members.

  NameDescription
Public methodMenuItemBindingInitializes a new instance of the MenuItemBinding class.
Top
  NameDescription
Public propertyDataMemberGets or sets the data member to bind to a menu item.
Public propertyDepthGets or sets the menu depth to which the MenuItemBinding object is applied.
Public propertyEnabledGets or sets a value that indicates whether the menu item to which the MenuItemBinding object is applied is enabled, allowing the item to display a pop-out image and any child menu items.
Public propertyEnabledFieldGets or sets the name of the field from the data source to bind to the Enabled property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertyFormatStringGets or sets the string that specifies the display format for the text of a menu item to which the MenuItemBinding object is applied.
Public propertyImageUrlGets or sets the URL to an image that is displayed next to the text of a menu item to which the MenuItemBinding object is applied.
Public propertyImageUrlFieldGets or sets the name of the field from the data source to bind to the ImageUrl property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertyNavigateUrlGets or sets the URL to link to when a menu item to which the MenuItemBinding object is applied is clicked.
Public propertyNavigateUrlFieldGets or sets the name of the field from the data source to bind to the NavigateUrl property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertyPopOutImageUrlGets or sets the URL to an image that indicates the presence of a dynamic submenu for a menu item to which the MenuItemBinding object is applied.
Public propertyPopOutImageUrlFieldGets or sets the name of the field from the data source to bind to the PopOutImageUrl property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertySelectableGets or sets a value that indicates whether the menu item to which the MenuItemBinding object is applied can be selected, or is "clickable."
Public propertySelectableFieldGets or sets the name of the field from the data source to bind to the Selectable property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertySeparatorImageUrlGets or sets the URL to an image displayed below the text of a menu item (to separate it from other menu items) for a menu item to which the MenuItemBinding object is applied.
Public propertySeparatorImageUrlFieldGets or sets the name of the field from the data source to bind to the SeparatorImageUrl property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertyTargetGets or sets the target window or frame in which to display the Web page content associated with a menu item to which the MenuItemBinding object is applied.
Public propertyTargetFieldGets or sets the name of the field from the data source to bind to the Target property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertyTextGets or sets the text displayed for the menu item to which the MenuItemBinding object is applied.
Public propertyTextFieldGets or sets the name of the field from the data source to bind to the Text property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertyToolTipGets or sets the ToolTip text for a menu item to which the MenuItemBinding object is applied.
Public propertyToolTipFieldGets or sets the name of the field from the data source to bind to the ToolTip property of a MenuItem object to which the MenuItemBinding object is applied.
Public propertyValueGets or sets a nondisplayed value used to store any additional data about a menu item to which the MenuItemBinding object is applied, such as data used for handling postback events.
Public propertyValueFieldGets or sets the name of the field from the data source to bind to the Value property of a MenuItem object to which the MenuItemBinding object is applied.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the MenuItemBinding object. (Overrides Object..::.ToString()()().)
Top
  NameDescription
Explicit interface implemetationPrivate methodICloneable..::.CloneInfrastructure. Creates a copy of the MenuItemBinding object.
Explicit interface implemetationPrivate propertyIDataSourceViewSchemaAccessor..::.DataSourceViewSchemaFor a description of this member, see DataSourceViewSchema.
Explicit interface implemetationPrivate propertyIStateManager..::.IsTrackingViewStateInfrastructure. Gets a value that indicates whether the MenuItemBinding object is saving changes to its view state.
Explicit interface implemetationPrivate methodIStateManager..::.LoadViewStateLoads the node's previously saved view state.
Explicit interface implemetationPrivate methodIStateManager..::.SaveViewStateInfrastructure. Saves the view state changes to an Object.
Explicit interface implemetationPrivate methodIStateManager..::.TrackViewStateInfrastructure. Instructs the MenuItemBinding object to track changes to its view state.
Top

When the Menu control is bound to a data source where each data item contains multiple fields (such as an XML element with several attributes), if no menu item bindings are defined, 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, but is not very useful otherwise. You can bind the properties of a menu item to a specific field by specifying menu item bindings. A MenuItemBinding object defines the relationship between each data item and the menu item it is binding to.

NoteNote

When the Menu control is bound to a SiteMapDataSource control, menu item bindings have no effect. Binding is performed automatically using the site map provider.

The Menu control stores its MenuItemBinding objects in the DataBindings property and applies the bindings to the data source to create a one-to-one relationship between the menu hierarchy and the data source hierarchy. For each data item in the data source, the Menu control attempts to match the data item to a MenuItemBinding object to create the corresponding MenuItem object.

When creating a MenuItemBinding object, you must specify the criteria for binding. The criteria indicate when a data item should be bound to a menu item. You can specify the Depth, the DataMember, or both.

A menu item depth specifies the menu level that gets bound. For example, the following MenuItemBinding declaration binds the Name and ID fields of the data source to the Text and Value properties, respectively, of all nodes with a depth of 0:

<asp:MenuItemBinding Depth="0" TextField="Name" ValueField="ID">

A data member specifies the type of the data item in the underlying data source, but can represent different information depending on the data source. Each data item in a hierarchical data source (represented by an IHierarchyData object) exposes a Type property, which specifies the type of the data item. For example, the data member for an XML element specifies the name of the element. When a data source contains multiple data item types, the data member specifies which data item type to use. The following MenuItemBinding declaration binds the <Book> elements of an XmlDataSource control to all the menu items in the menu, regardless of the location in the hierarchy:

<asp:MenuItemBinding DataMember="Book" TextField="Title" ValueField= "ISBN">

Sometimes you might need to create a menu item binding that specifies both a depth and a data member. This is often used when the data source contains items at different levels that have the same data member value. For example, you can have <Item> elements that appear at different levels within an XML file. The following MenuItemBinding declarations show how to specify menu item bindings that apply to identical data members at different menu depths:

<asp:MenuItemBinding DataMember="Item" Depth="1" TextField="Title">

<asp:MenuItemBinding DataMember="Item" Depth="2" TextField="ISBN">

If a menu item binding is defined without a depth and a data member, the menu item binding is applied to all menu items within the menu. This is commonly used when all data items have the same properties and should be displayed identically, regardless of the menu depth.

After the binding criteria are established, you can then bind a property of a MenuItem object that can be bound to a value. You can bind to a field of a data item or to a static value. When bound to a static value, all MenuItem objects to which the MenuItemBinding object is applied share the same value. Properties bound to fields contain the values of the corresponding field from the data source.

NoteNote

You can selectively override a bound property in a MenuItem object by setting the corresponding property directly.

The following table lists the properties of the MenuItemBinding class that allow you to bind a property of the MenuItem object to a field of a data item.

Property

Description

ImageUrlField

The field to bind to the ImageUrl property of a MenuItem object.

NavigateUrlField

The field to bind to the NavigateUrl property of a MenuItem object.

TextField

The field to bind to the Text property of a MenuItem object.

ToolTipField

The field to bind to the ToolTip property of a MenuItem object.

ValueField

The field to bind to the Value property of a MenuItem object.

The following table lists the properties of the MenuItemBinding class that allow you to bind a property of the MenuItem object to a static value.

Property

Description

ImageUrl

The static value to bind to the ImageUrl property of a MenuItem object.

NavigateUrl

The static value to bind to the NavigateUrl property of a MenuItem object.

Target

The static value to bind to the Target property of a MenuItem object.

Text

The static value to bind to the Text property of a MenuItem object.

ToolTip

The static value to bind to the ToolTip property of a MenuItem object.

Value

The static value to bind to the Value property of a MenuItem object.

If conflicting MenuItemBinding objects are defined, the Menu control applies the menu item bindings in the following order of precedence:

  1. The MenuItemBinding object that defines and matches both a depth and a data member.

  2. The MenuItemBinding object that defines and matches the data member only.

  3. The MenuItemBinding object that defines and matches the depth only.

  4. The MenuItemBinding object that defines neither the depth nor the data member. (This type of menu item binding is applied to all menu items in the menu.)

  5. The MenuItemBinding object that does not have a match in the data source. In this case, the value returned by the ToString() method of the data item is then bound to the Text and Value properties of the menu items to which the MenuItemBinding object is applied.

The MenuItemBinding class also allows you to format the text displayed in a menu item by setting the FormatString property.

TopicLocation
Procédure pas à pas : affichage d'un menu sur des pages WebGénération d'applications Web ASP.NET dans Visual Studio
Procédure pas à pas : affichage d'un menu sur des pages WebGénération d'applications à l'aide de Visual Web Developer
Procédure pas à pas : contrôle des menus ASP.NET par programmeGénération d'applications Web ASP.NET dans Visual Studio
Procédure pas à pas : contrôle des menus ASP.NET par programmeGénération d'applications Web ASP.NET dans Visual Studio

The following code example demonstrates how to use MenuItemBinding objects to define the relationship between the fields of an XmlDataSource control and the menu items in a Menu control. For this example to work correctly, you must copy the sample XML data below to a file named Menu.xml.

Visual Basic

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">

        <DataBindings>

          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>

        </DataBindings>

      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </form>
  </body>
</html>

C#

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">

        <DataBindings>

          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>

        </DataBindings>

      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </form>
  </body>
</html>

The following code is sample site map data for the previous example.

<MapHomeNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapHomeNode>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

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.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Bibliothèque de classes .NET Framework
MenuItemBinding, classe

Définit la relation entre un élément de données et l'élément de menu auquel il est lié dans un contrôle Menu. Cette classe ne peut pas être héritée.

System..::.Object
  System.Web.UI.WebControls..::.MenuItemBinding

Espace de noms :  System.Web.UI.WebControls
Assembly :  System.Web (dans System.Web.dll)
Visual Basic
Public NotInheritable Class MenuItemBinding _
    Implements IStateManager, ICloneable, IDataSourceViewSchemaAccessor
C#
public sealed class MenuItemBinding : IStateManager, 
    ICloneable, IDataSourceViewSchemaAccessor
VisualC++
public ref class MenuItemBinding sealed : IStateManager, 
    ICloneable, IDataSourceViewSchemaAccessor
F#
[<Sealed>]
type MenuItemBinding =  
    class
        interface IStateManager
        interface ICloneable
        interface IDataSourceViewSchemaAccessor
    end

Le type MenuItemBinding expose les membres suivants.

  NomDescription
Méthode publiqueMenuItemBindingInitialise une nouvelle instance de la classe MenuItemBinding.
Début
  NomDescription
Propriété publiqueDataMemberObtient ou définit la donnée membre à lier à un élément de menu.
Propriété publiqueDepthObtient ou définit la profondeur de menu à laquelle l'objet MenuItemBinding est appliqué.
Propriété publiqueEnabledObtient ou définit une valeur qui indique si l'élément de menu auquel l'objet MenuItemBinding est appliqué est activé, ce qui permet à l'élément d'afficher une image contextuelle et tous les éléments de menu enfants.
Propriété publiqueEnabledFieldObtient ou définit le nom du champ de la source de données à lier à la propriété Enabled d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueFormatStringObtient ou définit la chaîne qui spécifie le format d'affichage du texte d'un élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueImageUrlObtient ou définit l'URL d'une image qui est affichée près du texte d'un élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueImageUrlFieldObtient ou définit le nom du champ de la source de données à lier à la propriété ImageUrl d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueNavigateUrlObtient ou définit l'URL vers laquelle effectuer le lien lorsqu'un clic est effectué sur un élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueNavigateUrlFieldObtient ou définit le nom du champ de la source de données à lier à la propriété NavigateUrl d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiquePopOutImageUrlObtient ou définit l'URL d'une image qui indique la présence d'un sous-menu dynamique pour un élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiquePopOutImageUrlFieldObtient ou définit le nom du champ de la source de données à lier à la propriété PopOutImageUrl d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueSelectableObtient ou définit une valeur qui indique si l'élément de menu auquel l'objet MenuItemBinding est appliqué peut être sélectionné, ou s'il est « interactif ».
Propriété publiqueSelectableFieldObtient ou définit le nom du champ de la source de données à lier à la propriété Selectable d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueSeparatorImageUrlObtient ou définit l'URL d'une image affichée au-dessous du texte d'un élément de menu (pour le séparer d'autres éléments de menu) pour un élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueSeparatorImageUrlFieldObtient ou définit le nom du champ de la source de données à lier à la propriété SeparatorImageUrl d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueTargetObtient ou définit la fenêtre ou frame cible dans lequel afficher le contenu de la page Web associée à un élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueTargetFieldObtient ou définit le nom du champ de la source de données à lier à la propriété Target d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueTextObtient ou définit le texte affiché de l'élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueTextFieldObtient ou définit le nom du champ de la source de données à lier à la propriété Text d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueToolTipObtient ou définit le texte info-bulle d'un l'élément de menu auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueToolTipFieldObtient ou définit le nom du champ de la source de données à lier à la propriété ToolTip d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Propriété publiqueValueObtient ou définit une valeur non affichée utilisée pour stocker des données supplémentaires relatives à un élément de menu auquel l'objet MenuItemBinding est appliqué, telles que les données utilisées pour gérer les événements de publication (postback).
Propriété publiqueValueFieldObtient ou définit le nom du champ de la source de données à lier à la propriété Value d'un objet MenuItem auquel l'objet MenuItemBinding est appliqué.
Début
  NomDescription
Méthode publiqueEquals(Object)Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.)
Méthode protégéeFinalizeAutorise 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.)
Méthode publiqueGetHashCodeSert de fonction de hachage pour un type particulier. (Hérité de Object.)
Méthode publiqueGetTypeObtient le Type de l'instance actuelle. (Hérité de Object.)
Méthode protégéeMemberwiseCloneCrée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode publiqueToStringRetourne une chaîne qui représente l'objet MenuItemBinding. (Substitue Object..::.ToString()()().)
Début
  NomDescription
Implémentation d'interface expliciteMéthode privéeICloneable..::.CloneInfrastructure. Crée une copie de l'objet MenuItemBinding.
Implémentation d'interface explicitePropriété privéeIDataSourceViewSchemaAccessor..::.DataSourceViewSchemaPour obtenir une description de ce membre, consultez DataSourceViewSchema.
Implémentation d'interface explicitePropriété privéeIStateManager..::.IsTrackingViewStateInfrastructure. Obtient une valeur qui indique si l'objet MenuItemBinding enregistre les modifications apportées à son état d'affichage.
Implémentation d'interface expliciteMéthode privéeIStateManager..::.LoadViewStateCharge l'état d'affichage précédemment enregistré du nœud.
Implémentation d'interface expliciteMéthode privéeIStateManager..::.SaveViewStateInfrastructure. Enregistre les modifications d'état d'affichage apportées à un Object.
Implémentation d'interface expliciteMéthode privéeIStateManager..::.TrackViewStateInfrastructure. Indique à l'objet MenuItemBinding d'assurer le suivi des modifications de son état d'affichage.
Début

Lorsque le contrôle Menu est lié à une source de données où chaque élément de données contient plusieurs champs (tel qu'un élément XML avec plusieurs attributs), si aucune liaison d'élément de menu n'est définie, 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 du menu, mais n'est pas pour autant très utile. Vous pouvez lier les propriétés d'un élément de menu à un champ spécifique en spécifiant des liaisons d'élément de menu. Un objet MenuItemBinding définit la relation entre chaque élément de données et l'élément de menu auquel il est lié.

RemarqueRemarque

Lorsque le contrôle Menu est lié à un contrôle SiteMapDataSource, les liaisons d'élément de menu n'ont aucun effet. La liaison est effectuée automatiquement à l'aide du fournisseur de plan de site.

Le contrôle Menu stocke ses objets MenuItemBinding dans la propriété DataBindings et applique les liaisons à la source de données afin de créer une relation un-à-un entre la hiérarchie de menus et la hiérarchie des sources de données. Pour chaque élément de données de la source de données, le contrôle Menu tente de faire correspondre l'élément de données à un objet MenuItemBinding afin de créer l'objet MenuItem correspondant.

Lorsque vous créez un objet MenuItemBinding, vous devez spécifier les critères de liaison. Les critères indiquent à quel moment un élément de données doit être lié à un élément de menu. Vous pouvez spécifier Depth, DataMember ou les deux.

Une profondeur de l'élément de menu spécifie le niveau de menu qui est lié. Par exemple, la déclaration MenuItemBinding suivante lie les champs ID et Nom de la source de données aux propriétés Text et Value, respectivement, de tous les nœuds d'une profondeur de 0 :

<asp:MenuItemBinding Depth="0" TextField="Name" ValueField="ID">

Une donnée membre spécifie le type de l'élément de données dans la source de données sous-jacente, mais peut également représenter des informations différentes selon la source de données. Chaque élément de données dans une source de données hiérarchique (représenté par un objet IHierarchyData) expose une propriété Type qui spécifie le type de l'élément de données. Par exemple, la donnée membre d'un élément XML spécifie le nom de l'élément. Lorsqu'une source de données contient plusieurs types d'éléments de données, les données membres spécifient le type d'élément de données à utiliser. La déclaration MenuItemBinding suivante lie les éléments <Book> d'un contrôle XmlDataSource à tous les éléments de menu dans le menu, indépendamment de l'emplacement dans la hiérarchie :

<asp:MenuItemBinding DataMember="Book" TextField="Title" ValueField= "ISBN">

Parfois vous pouvez avoir à créer une liaison d'élément de menu qui spécifie à la fois une profondeur et une donnée membre. Cette tâche est souvent utilisée lorsque la source de données contient des éléments à différents niveaux qui ont la même valeur de donnée membre. Par exemple, vous pouvez avoir des éléments <Item> qui apparaissent à des niveaux différents dans un fichier XML. Les déclarations MenuItemBinding suivantes indiquent comment spécifier des liaisons d'élément de menu qui s'appliquent à des données membres identiques à des profondeurs de menu différentes :

<asp:MenuItemBinding DataMember="Item" Depth="1" TextField="Title">

<asp:MenuItemBinding DataMember="Item" Depth="2" TextField="ISBN">

Si une liaison d'élément de menu est définie sans profondeur et sans donnée membre, la liaison d'élément de menu est appliquée à tous les éléments de menu dans le menu. Cela est généralement utilisé lorsque tous les éléments de données ont les mêmes propriétés et doivent être affichés de la même manière, indépendamment de la profondeur de menu.

Une fois les critères de liaison établis, vous pouvez ensuite lier une propriété d'un objet MenuItem qui peut être lié à une valeur. Vous pouvez lier à un champ d'un élément de données ou à une valeur statique. Lorsqu'ils sont liés à une valeur statique, tous les objets MenuItem auxquels l'objet MenuItemBinding est appliqué partagent la même valeur. Les propriétés liées aux champs contiennent les valeurs du champ correspondant de la source de données.

RemarqueRemarque

Vous pouvez substituer sélectivement une propriété liée dans un objet MenuItem en définissant la propriété correspondante directement.

Le tableau suivant répertorie les propriétés de la classe MenuItemBinding qui vous permet de lier une propriété de l'objet MenuItem à un champ d'un élément de données.

Propriété

Description

ImageUrlField

Champ à lier à la propriété ImageUrl d'un objet MenuItem.

NavigateUrlField

Champ à lier à la propriété NavigateUrl d'un objet MenuItem.

TextField

Champ à lier à la propriété Text d'un objet MenuItem.

ToolTipField

Champ à lier à la propriété ToolTip d'un objet MenuItem.

ValueField

Champ à lier à la propriété Value d'un objet MenuItem.

Le tableau suivant répertorie les propriétés de la classe MenuItemBinding qui vous permet de lier une propriété de l'objet MenuItem à une valeur statique.

Propriété

Description

ImageUrl

Valeur statique à lier à la propriété ImageUrl d'un objet MenuItem.

NavigateUrl

Valeur statique à lier à la propriété NavigateUrl d'un objet MenuItem.

Target

Valeur statique à lier à la propriété Target d'un objet MenuItem.

Text

Valeur statique à lier à la propriété Text d'un objet MenuItem.

ToolTip

Valeur statique à lier à la propriété ToolTip d'un objet MenuItem.

Value

Valeur statique à lier à la propriété Value d'un objet MenuItem.

Si les objets MenuItemBinding en conflit sont définis, le contrôle Menu applique les liaisons d'élément de menu dans l'ordre de priorité suivant :

  1. Objet MenuItemBinding qui définit et correspond une profondeur et une donnée membre.

  2. Objet MenuItemBinding qui définit et correspond à la donnée membre uniquement.

  3. Objet MenuItemBinding qui définit et correspond à la profondeur uniquement.

  4. Objet MenuItemBinding qui ne définit ni la profondeur, ni les données membres. (Ce type de liaison d'élément de menu est appliqué à tous les éléments de menu dans le menu.)

  5. Objet MenuItemBinding qui n'a pas de correspondance dans la source de données. Dans ce cas, la valeur retournée par la méthode ToString() de l'élément de données est ensuite liée aux propriétés Text et Value des éléments de menu auxquels l'objet MenuItemBinding est appliqué.

La classe MenuItemBinding vous permet également de mettre en forme le texte affiché dans un élément de menu en définissant la propriété FormatString.

TopicLocation
Procédure pas à pas : affichage d'un menu sur des pages WebGénération d'applications Web ASP.NET dans Visual Studio
Procédure pas à pas : affichage d'un menu sur des pages WebGénération d'applications à l'aide de Visual Web Developer
Procédure pas à pas : contrôle des menus ASP.NET par programmeGénération d'applications Web ASP.NET dans Visual Studio
Procédure pas à pas : contrôle des menus ASP.NET par programmeGénération d'applications Web ASP.NET dans Visual Studio

L'exemple de code suivant illustre comment utiliser des objets MenuItemBinding pour définir la relation entre les champs d'un contrôle XmlDataSource et les éléments de menu d'un contrôle Menu. Pour que cet exemple fonctionne, vous devez copier l'exemple de données XML ci-dessous dans un fichier nommé Menu.xml.

Visual Basic

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">

        <DataBindings>

          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>

        </DataBindings>

      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </form>
  </body>
</html>

C#

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">

        <DataBindings>

          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>

        </DataBindings>

      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </form>
  </body>
</html>

Le code suivant est un exemple de données de plan de site de l'exemple précédent.

<MapHomeNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapHomeNode>

.NET Framework

Pris en charge dans : 4, 3.5, 3.0, 2.0

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.
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.
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2012 Microsoft. Tous droits réservés. Conditions d'utilisation | Marques | Confidentialité
Page view tracker