This topic has not yet been rated - Rate this topic

MenuEventArgs Class

Provides data for the MenuItemClick and MenuItemDataBound events of a Menu control. This class cannot be inherited.

System.Object
  System.EventArgs
    System.Web.UI.WebControls.CommandEventArgs
      System.Web.UI.WebControls.MenuEventArgs

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
public sealed class MenuEventArgs : CommandEventArgs

The MenuEventArgs type exposes the following members.

  Name Description
Public method MenuEventArgs(MenuItem) Initializes a new instance of the MenuEventArgs class using the specified menu item.
Public method MenuEventArgs(MenuItem, Object, CommandEventArgs) Initializes a new instance of the MenuEventArgs class using the specified menu item, command source, and event arguments.
Top
  Name Description
Public property CommandArgument Gets the argument for the command. (Inherited from CommandEventArgs.)
Public property CommandName Gets the name of the command. (Inherited from CommandEventArgs.)
Public property CommandSource Gets the Object that raised the event.
Public property Item Gets the menu item associated with the event raised.
Top
  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top

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.

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="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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>

.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 not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), 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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ