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
MenuItemCollection, 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
MenuItemCollection Class

Represents a collection of menu items in a Menu control. This class cannot be inherited.

System..::.Object
  System.Web.UI.WebControls..::.MenuItemCollection

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

The MenuItemCollection type exposes the following members.

  NameDescription
Public methodMenuItemCollection()()()Initializes a new instance of the MenuItemCollection class using the default values.
Public methodMenuItemCollection(MenuItem)Initializes a new instance of the MenuItemCollection class using the specified parent menu item (or owner).
Top
  NameDescription
Public propertyCountGets the number of menu items contained in the current MenuItemCollection object.
Public propertyIsSynchronizedGets a value indicating whether access to the MenuItemCollection object is synchronized (thread safe).
Public propertyItemGets the MenuItem object at the specified index in the current MenuItemCollection object.
Public propertySyncRootGets an object that can be used to synchronize access to the MenuItemCollection object.
Top
  NameDescription
Public methodAddAppends the specified MenuItem object to the end of the current MenuItemCollection object.
Public methodAddAtInserts the specified MenuItem object in the current MenuItemCollection object at the specified index location.
Public methodClearRemoves all items from the current MenuItemCollection object.
Public methodContainsDetermines whether the specified MenuItem object is in the collection.
Public methodCopyTo(Array, Int32)Copies all the items from the MenuItemCollection object to a compatible one-dimensional Array, starting at the specified index in the target array.
Public methodCopyTo(array<MenuItem>[]()[], Int32)Copies all the items from the MenuItemCollection object to a compatible one-dimensional array of MenuItem objects, starting at the specified index in the target array.
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 methodGetEnumeratorReturns an enumerator that can be used to iterate through the items in the current MenuItemCollection 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.)
Public methodIndexOfDetermines the index of the specified MenuItem object in the collection.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveRemoves the specified MenuItem object from the MenuItemCollection object.
Public methodRemoveAtRemoves the MenuItem object at the specified index location from the current MenuItemCollection object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<(Of <(TResult>)>)Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<(Of <(TResult>)>)Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
  NameDescription
Explicit interface implemetationPrivate propertyIStateManager..::.IsTrackingViewStateInfrastructure. Gets a value that indicates whether the MenuItemCollection object is saving changes to its view state.
Explicit interface implemetationPrivate methodIStateManager..::.LoadViewStateInfrastructure. Loads the MenuItemCollection object's previously saved view state.
Explicit interface implemetationPrivate methodIStateManager..::.SaveViewStateInfrastructure. Saves the changes to view state to an Object.
Explicit interface implemetationPrivate methodIStateManager..::.TrackViewStateInfrastructure. Instructs the MenuItemCollection object to track changes to its view state.
Top

The MenuItemCollection class is used to store and manage a collection of MenuItem objects in the Menu control. The Menu control uses the MenuItemCollection class to store its root menu items in the Items property. This collection is also used for the ChildItems property of a MenuItem object to store a menu item's submenu items (if any).

The MenuItemCollection class supports several ways to access the items in the collection:

  • Use the Item indexer to directly retrieve a MenuItem object at a specific zero-based index.

  • Use the GetEnumerator method to create an enumerator that can be used to iterate through the collection.

  • Use the CopyTo method to copy the contents of the collection into an array.

You can programmatically manage a MenuItemCollection object by adding and removing MenuItem objects. To add menu items to the collection, use the Add or the AddAt method. To remove nodes from the collection, use the Remove, the RemoveAt, or the Clear method.

NoteNote

When the Menu control is bound to a data source, the Items and ChildItems collections are automatically populated each time binding occurs. Any changes to the collections between bindings will be lost. To retain these changes, either update the data source or manually rebuild the collection each time you bind.

The MenuItemCollection class contains properties and methods that allow you to retrieve information about the collection itself. To find out how many items are in the collection, use the Count property. If you want to determine whether the collection contains a certain MenuItem object, use the Contains method. To get the index of a MenuItem object in the collection, use the IndexOf method.

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 populate the Items and ChildItems collections using declarative syntax.

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  >

  <!-- 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>

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  >

  <!-- 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 programmatically add a MenuItem object to the ChildItems collection of a root menu item.

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">
<script runat="server">

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    If Not IsPostBack Then

      ' Retrieve the root menu item from the Items
      ' collection of the Menu control using the indexer.
      Dim homeMenuItem As MenuItem = NavigationMenu.Items(0)

      ' Create the submenu item.
      Dim newSubMenuItem = New MenuItem("New Category")

      ' Add the submenu item to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(newSubMenuItem)

    End If

  End Sub

</script>

<html  >
  <head runat="server">
    <title>MenuItemCollection Add Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemCollection Add Example</h3>

      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server">

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>

      </asp:menu>

    </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">
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {
    if (!IsPostBack)
    {
      // Retrieve the root menu item from the Items
      // collection of the Menu control using the indexer.
      MenuItem homeMenuItem = NavigationMenu.Items[0];

      // Create the submenu item.
      MenuItem newSubMenuItem = new MenuItem("New Category");

      // Add the submenu item to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(newSubMenuItem);
    }
  }

</script>

<html  >
  <head runat="server">
    <title>MenuItemCollection Add Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemCollection Add Example</h3>

      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server">

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>

      </asp:menu>

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

.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
MenuItemCollection, classe

Représente une collection d'éléments de menu dans un contrôle Menu. Cette classe ne peut pas être héritée.

System..::.Object
  System.Web.UI.WebControls..::.MenuItemCollection

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

Le type MenuItemCollection expose les membres suivants.

  NomDescription
Méthode publiqueMenuItemCollection()()()Initialise une nouvelle instance de la classe MenuItemCollection à l'aide des valeurs par défaut.
Méthode publiqueMenuItemCollection(MenuItem)Initialise une nouvelle instance de la classe MenuItemCollection à l'aide de l'élément de menu parent (ou propriétaire) spécifié.
Début
  NomDescription
Propriété publiqueCountObtient le nombre d'éléments de menu contenus dans l'objet MenuItemCollection en cours.
Propriété publiqueIsSynchronizedObtient une valeur indiquant si l'accès à l'objet MenuItemCollection est synchronisé (thread-safe).
Propriété publiqueItemObtient l'objet MenuItem à l'index spécifié dans l'objet MenuItemCollection en cours.
Propriété publiqueSyncRootObtient un objet qui peut être utilisé pour synchroniser l'accès à l'objet MenuItemCollection.
Début
  NomDescription
Méthode publiqueAddAjoute l'objet MenuItem spécifié à la fin de l'objet MenuItemCollection en cours.
Méthode publiqueAddAtInsère l'objet MenuItem spécifié dans l'objet MenuItemCollection en cours à l'emplacement d'index spécifié.
Méthode publiqueClearSupprime tous les éléments de l'objet MenuItemCollection en cours.
Méthode publiqueContainsDétermine si l'objet MenuItem spécifié se trouve dans la collection.
Méthode publiqueCopyTo(Array, Int32)Copie tous les éléments de l'objet MenuItemCollection dans un tableau Array compatible unidimensionnel, en commençant à l'index spécifié dans le tableau cible.
Méthode publiqueCopyTo(array<MenuItem>[]()[], Int32)Copie tous les éléments de l'objet MenuItemCollection dans un tableau d'objets MenuItem compatible unidimensionnel, en commençant à l'index spécifié dans le tableau cible.
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 publiqueGetEnumeratorRetourne un énumérateur qui peut être utilisé pour itérer au sein des éléments de l'objet MenuItemCollection en cours.
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 publiqueIndexOfDétermine l'index de l'objet MenuItem spécifié dans la collection.
Méthode protégéeMemberwiseCloneCrée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode publiqueRemoveSupprime l'objet MenuItem spécifié de l'objet MenuItemCollection.
Méthode publiqueRemoveAtSupprime l'objet MenuItem à l'emplacement d'index spécifié de l'objet MenuItemCollection en cours.
Méthode publiqueToStringRetourne une chaîne qui représente l'objet actuel. (Hérité de Object.)
Début
  NomDescription
Méthode d'extension publiqueAsParallelActive la parallélisation d'une requête. (Défini par ParallelEnumerable.)
Méthode d'extension publiqueAsQueryableConvertit un IEnumerable en IQueryable. (Défini par Queryable.)
Méthode d'extension publiqueCast<(Of <(TResult>)>)Convertit les éléments d'un IEnumerable vers le type spécifié. (Défini par Enumerable.)
Méthode d'extension publiqueOfType<(Of <(TResult>)>)Filtre les éléments d'un IEnumerable en fonction du type spécifié. (Défini par Enumerable.)
Début
  NomDescription
Implémentation d'interface explicitePropriété privéeIStateManager..::.IsTrackingViewStateInfrastructure. Obtient une valeur qui indique si l'objet MenuItemCollection enregistre les modifications apportées à son état d'affichage.
Implémentation d'interface expliciteMéthode privéeIStateManager..::.LoadViewStateInfrastructure. Charge l'état d'affichage précédemment enregistré de l'objet MenuItemCollection.
Implémentation d'interface expliciteMéthode privéeIStateManager..::.SaveViewStateInfrastructure. Enregistre les modifications apportées à l'état d'affichage dans Object.
Implémentation d'interface expliciteMéthode privéeIStateManager..::.TrackViewStateInfrastructure. Demande à l'objet MenuItemCollection d'assurer le suivi des modifications apportées à son état d'affichage.
Début

La classe MenuItemCollection est utilisée pour stocker et gérer une collection d'objets MenuItem dans le contrôle Menu. Le contrôle Menu utilise la classe MenuItemCollection pour stocker ses éléments de menu racine dans la propriété Items. Cette collection est utilisée également pour la propriété ChildItems d'un objet MenuItem pour stocker les éléments de sous-menu d'un élément de menu (le cas échéant).

La classe MenuItemCollection prend en charge plusieurs modes d'accès aux éléments de la collection :

  • Utilisez l'indexeur Item pour récupérer directement un objet MenuItem à un index de base zéro spécifique.

  • Utilisez la méthode GetEnumerator afin de créer un énumérateur qui peut être utilisé pour itérer au sein de la collection.

  • Utilisez la méthode CopyTo pour copier le contenu de la collection dans un tableau.

Vous pouvez gérer par programme un objet MenuItemCollection en ajoutant et en supprimant des objets MenuItem. Pour ajouter des éléments de menu à la collection, utilisez les méthodes Add ou AddAt. Pour supprimer des nœuds de la collection, utilisez les méthodes Remove, RemoveAt ou Clear.

RemarqueRemarque

Lorsque le contrôle Menu est lié à une source de données, les collections Items et ChildItems sont automatiquement remplies à chaque liaison. Toutes les modifications apportées aux collections entre deux liaisons seront perdues. Pour conserver ces modifications, mettez à jour la source de données ou régénérez manuellement la collection à chaque liaison.

La classe MenuItemCollection contient des propriétés et des méthodes qui vous permettent de récupérer des informations sur la collection proprement dite. Pour déterminer le nombre d'éléments contenus dans la collection, utilisez la propriété Count. Pour déterminer si la collection contient un certain objet MenuItem, utilisez la méthode Contains. Pour obtenir l'index d'un objet MenuItem dans la collection, utilisez la méthode IndexOf.

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 montre comment remplir les collections Items et ChildItems à l'aide d'une syntaxe déclarative.

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  >

  <!-- 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>

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  >

  <!-- 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 ajouter par programme un objet MenuItem à la collection ChildItems d'un élément de menu racine.

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">
<script runat="server">

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    If Not IsPostBack Then

      ' Retrieve the root menu item from the Items
      ' collection of the Menu control using the indexer.
      Dim homeMenuItem As MenuItem = NavigationMenu.Items(0)

      ' Create the submenu item.
      Dim newSubMenuItem = New MenuItem("New Category")

      ' Add the submenu item to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(newSubMenuItem)

    End If

  End Sub

</script>

<html  >
  <head runat="server">
    <title>MenuItemCollection Add Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemCollection Add Example</h3>

      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server">

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>

      </asp:menu>

    </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">
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {
    if (!IsPostBack)
    {
      // Retrieve the root menu item from the Items
      // collection of the Menu control using the indexer.
      MenuItem homeMenuItem = NavigationMenu.Items[0];

      // Create the submenu item.
      MenuItem newSubMenuItem = new MenuItem("New Category");

      // Add the submenu item to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(newSubMenuItem);
    }
  }

</script>

<html  >
  <head runat="server">
    <title>MenuItemCollection Add Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemCollection Add Example</h3>

      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server">

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>

      </asp:menu>

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

.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