.NET Framework Class Library MenuEventArgs Class

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

Syntax
Public NotInheritable Class MenuEventArgs _
Inherits CommandEventArgs
public sealed class MenuEventArgs : CommandEventArgs
public ref class MenuEventArgs sealed : public CommandEventArgs
[<Sealed>]
type MenuEventArgs =
class
inherit CommandEventArgs
end
The MenuEventArgs type exposes the following members.

Constructors

Properties

Methods

Remarks
The MenuEventArgs class is used to store the event data passed to an event handler for the events in the following table. 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. |
Depending on the event raised, you can access the menu item clicked by the user or the menu item being bound to data by using the Item property. For a list of initial property values for an instance of the MenuEventArgs class, see the MenuEventArgs constructor.

Examples
The following code example demonstrates how to use the MenuEventArgs object passed to the event handler for the MenuItemDataBound event to modify the properties of a menu item before it is displayed in a Menu control. The ImageUrl property of the Home menu item is set to display an image in that menu item only. 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">
<script runat="server">
Sub MenuItemDataBound_NavigationMenu(ByVal sender As Object, ByVal e As MenuEventArgs)
' Display an image for the Home menu item only by
' setting its ImageUrl property.
If e.Item.Text = "Home" Then
e.Item.ImageUrl = "Images\Home.jpg"
End If
End Sub
</script>
<html >
<head runat="server">
<title>MenuEventArgs Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>MenuEventArgs Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
datasourceid="menusource"
onmenuitemdatabound="MenuItemDataBound_NavigationMenu"
runat="server">
</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">
<script runat="server">
void MenuItemDataBound_NavigationMenu(Object sender, MenuEventArgs e)
{
// Display an image for the Home menu item only by
// setting its ImageUrl property.
if (e.Item.Text == "Home")
{
// Use an @-quoted string to bypass the escape sequence
// processing.
e.Item.ImageUrl = @"Images\Home.jpg";
}
}
</script>
<html >
<head runat="server">
<title>MenuEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuEventArgs Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
datasourceid="menusource"
onmenuitemdatabound="MenuItemDataBound_NavigationMenu"
runat="server">
</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 MenuEventArgs, classe

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

Syntaxe
Public NotInheritable Class MenuEventArgs _
Inherits CommandEventArgs
public sealed class MenuEventArgs : CommandEventArgs
public ref class MenuEventArgs sealed : public CommandEventArgs
[<Sealed>]
type MenuEventArgs =
class
inherit CommandEventArgs
end
Le type MenuEventArgs expose les membres suivants.

Constructeurs

Propriétés

Méthodes

Notes
La classe MenuEventArgs est utilisée pour stocker les données d'événement passées à un gestionnaire d'événements pour les événements décrits dans le tableau suivant. É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. |
Selon l'événement déclenché, vous pouvez accéder à l'élément de menu sur lequel l'utilisateur a cliqué ou à l'élément de menu lié aux données en utilisant la propriété Item. Pour obtenir la liste des valeurs initiales des propriétés d'une instance de la classe MenuEventArgs, consultez le constructeur MenuEventArgs.

Exemples
L'exemple de code suivant montre comment utiliser l'objet MenuEventArgs passé au gestionnaire d'événements pour l'événement MenuItemDataBound pour modifier les propriétés d'un élément de menu avant qu'il soit affiché dans un contrôle Menu. La propriété ImageUrl de l'élément de menu Home est configurée pour afficher uniquement une image dans cet élément de menu. 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">
<script runat="server">
Sub MenuItemDataBound_NavigationMenu(ByVal sender As Object, ByVal e As MenuEventArgs)
' Display an image for the Home menu item only by
' setting its ImageUrl property.
If e.Item.Text = "Home" Then
e.Item.ImageUrl = "Images\Home.jpg"
End If
End Sub
</script>
<html >
<head runat="server">
<title>MenuEventArgs Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>MenuEventArgs Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
datasourceid="menusource"
onmenuitemdatabound="MenuItemDataBound_NavigationMenu"
runat="server">
</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">
<script runat="server">
void MenuItemDataBound_NavigationMenu(Object sender, MenuEventArgs e)
{
// Display an image for the Home menu item only by
// setting its ImageUrl property.
if (e.Item.Text == "Home")
{
// Use an @-quoted string to bypass the escape sequence
// processing.
e.Item.ImageUrl = @"Images\Home.jpg";
}
}
</script>
<html >
<head runat="server">
<title>MenuEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuEventArgs Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
datasourceid="menusource"
onmenuitemdatabound="MenuItemDataBound_NavigationMenu"
runat="server">
</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
|