Επεξεργασία

Κοινή χρήση μέσω


MenuItem Constructors

Definition

Initializes a new instance of the MenuItem class.

Overloads

MenuItem()

Initializes a new instance of the MenuItem class without menu text or a value.

MenuItem(String)

Initializes a new instance of the MenuItem class using the specified menu text.

MenuItem(String, String)

Initializes a new instance of the MenuItem class using the specified menu text and value.

MenuItem(String, String, String)

Initializes a new instance of the MenuItem class using the specified menu text, value, and URL to an image.

MenuItem(String, String, String, String)

Initializes a new instance of the MenuItem class using the specified menu text, value, image URL, and navigation URL.

MenuItem(String, String, String, String, String)

Initializes a new instance of the MenuItem class using the specified menu text, value, image URL, navigation URL, and target.

MenuItem()

Initializes a new instance of the MenuItem class without menu text or a value.

public:
 MenuItem();
public MenuItem ();
Public Sub New ()

Examples

The following example demonstrates how to use this constructor to create a new instance of the MenuItem class. The MenuItem object is then used to dynamically populate the menu items in a Menu control.


<%@ 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)
    {
      // Create the menu structure.

      // Create the root menu item.
      MenuItem homeMenuItem;
      homeMenuItem = CreateMenuItem("Home", "Home.aspx", "Home");

      // Create the submenu items.
      MenuItem musicSubMenuItem;
      musicSubMenuItem = CreateMenuItem("Music", "Music.aspx", "Music");

      MenuItem moviesSubMenuItem;
      moviesSubMenuItem = CreateMenuItem("Movies", "Movies.aspx", "Movies");

      // Add the submenu items to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem);
      homeMenuItem.ChildItems.Add(moviesSubMenuItem);

      // Add the root menu item to the Items collection 
      // of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem);
    }
  }
  
  MenuItem CreateMenuItem(String text, String url, String toolTip)
  {
    
    // Create a new MenuItem object.
    MenuItem menuItem = new MenuItem();
    
    // Set the properties of the MenuItem object using
    // the specified parameters.
    menuItem.Text = text;
    menuItem.NavigateUrl = url;
    menuItem.ToolTip = toolTip;
    
    return menuItem;
    
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

<%@ 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
      
      ' Create the menu structure.
    
      ' Create the root menu item.
      Dim homeMenuItem As MenuItem
      homeMenuItem = CreateMenuItem("Home", "Home.aspx", "Home")
    
      ' Create the submenu items.
      Dim musicSubMenuItem As MenuItem
      musicSubMenuItem = CreateMenuItem("Music", "Music.aspx", "Music")
    
      Dim moviesSubMenuItem As MenuItem
      moviesSubMenuItem = CreateMenuItem("Movies", "Movies.aspx", "Movies")
    
      ' Add the submenu items to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem)
      homeMenuItem.ChildItems.Add(moviesSubMenuItem)
    
      ' Add the root menu item to the Items collection 
      ' of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem)
      
    End If
    
  End Sub
  
  Function CreateMenuItem(ByVal text As String, ByVal url As String, ByVal toolTip As String) As MenuItem
    
    ' Create a new MenuItem object.
    Dim menuItem As New MenuItem()
    
    ' Set the properties of the MenuItem object using
    ' the specified parameters.
    MenuItem.Text = text
    MenuItem.NavigateUrl = url
    MenuItem.ToolTip = toolTip
    
    Return MenuItem
    
  End Function

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

Remarks

Use this constructor to create a new instance of a MenuItem class without menu text or a value.

Note

When this constructor is used, all properties in the MenuItem object are set to their default values. Be sure to set the properties, as necessary, after creating the object.

This constructor is commonly used when dynamically populating the Items collection of a Menu control or the ChildItems collection of a MenuItem object.

See also

Applies to

MenuItem(String)

Initializes a new instance of the MenuItem class using the specified menu text.

public:
 MenuItem(System::String ^ text);
public MenuItem (string text);
new System.Web.UI.WebControls.MenuItem : string -> System.Web.UI.WebControls.MenuItem
Public Sub New (text As String)

Parameters

text
String

The text displayed for a menu item in a Menu control.

Examples

The following example demonstrates how to use this constructor to create a new instance of the MenuItem class. The MenuItem object is then used to dynamically populate the menu items in a Menu control.


<%@ 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)
    {
      // Create the menu structure.

      // Create the root menu item.
      MenuItem homeMenuItem = new MenuItem("Home");

      // Create the submenu items.
      MenuItem musicSubMenuItem = new MenuItem("Music");
      MenuItem moviesSubMenuItem = new MenuItem("Movies");

      // Add the submenu items to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem);
      homeMenuItem.ChildItems.Add(moviesSubMenuItem);

      // Add the root menu item to the Items collection 
      // of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem);
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

<%@ 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
    
      ' Create the menu structure.

      ' Create the root menu item.
      Dim homeMenuItem As New MenuItem("Home")

      ' Create the submenu items.
      Dim musicSubMenuItem As New MenuItem("Music")
      Dim moviesSubMenuItem As New MenuItem("Movies")

      ' Add the submenu items to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem)
      homeMenuItem.ChildItems.Add(moviesSubMenuItem)

      ' Add the root menu item to the Items collection 
      ' of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem)
      
    End If
  
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

Remarks

Use this constructor to create a new instance of the MenuItem class using the menu text specified by the text parameter.

The following table shows the initial property value for an instance of the MenuItem class.

Property Initial value
Text The value of the text parameter.

This constructor is commonly used when dynamically populating the Items collection of a Menu control or the ChildItems collection of a MenuItem object.

See also

Applies to

MenuItem(String, String)

Initializes a new instance of the MenuItem class using the specified menu text and value.

public:
 MenuItem(System::String ^ text, System::String ^ value);
public MenuItem (string text, string value);
new System.Web.UI.WebControls.MenuItem : string * string -> System.Web.UI.WebControls.MenuItem
Public Sub New (text As String, value As String)

Parameters

text
String

The text displayed for a menu item in a Menu control.

value
String

The supplemental data associated with the menu item, such as data used for handling postback events.

Examples

The following example demonstrates how to use this constructor to create a new instance of the MenuItem class. The MenuItem object is then used to dynamically populate the menu items in a Menu control.


<%@ 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)
    {
      // Create the menu structure.

      // Create the root menu item.
      MenuItem homeMenuItem = new MenuItem("Home", "Root");

      // Create the submenu items.
      MenuItem musicSubMenuItem = new MenuItem("Music", "Category 1");
      MenuItem moviesSubMenuItem = new MenuItem("Movies", "Category 2");

      // Add the submenu items to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem);
      homeMenuItem.ChildItems.Add(moviesSubMenuItem);

      // Add the root menu item to the Items collection 
      // of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem);
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

<%@ 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
    
      ' Create the menu structure.

      ' Create the root menu item.
      Dim homeMenuItem As New MenuItem("Home", "Root")

      ' Create the submenu items.
      Dim musicSubMenuItem As New MenuItem("Music", "Category 1")
      Dim moviesSubMenuItem As New MenuItem("Movies", "Category 2")

      ' Add the submenu items to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem)
      homeMenuItem.ChildItems.Add(moviesSubMenuItem)

      ' Add the root menu item to the Items collection 
      ' of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem)
      
    End If
  
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

Remarks

Use this constructor to create a new instance of the MenuItem class using the menu text and value specified by the text and value parameters, respectively.

The following table shows initial property values for an instance of the MenuItem class.

Property Initial value
Text The value of the text parameter.
Value The value of the value parameter.

This constructor is commonly used when dynamically populating the Items collection of a Menu control or the ChildItems collection of a MenuItem object.

See also

Applies to

MenuItem(String, String, String)

Initializes a new instance of the MenuItem class using the specified menu text, value, and URL to an image.

public:
 MenuItem(System::String ^ text, System::String ^ value, System::String ^ imageUrl);
public MenuItem (string text, string value, string imageUrl);
new System.Web.UI.WebControls.MenuItem : string * string * string -> System.Web.UI.WebControls.MenuItem
Public Sub New (text As String, value As String, imageUrl As String)

Parameters

text
String

The text displayed for a menu item in a Menu control.

value
String

The supplemental data associated with the menu item, such as data used for handling postback events.

imageUrl
String

The URL to an image displayed next to the text in a menu item.

Examples

The following example demonstrates how to use this constructor to create a new instance of the MenuItem class. The MenuItem object is then used to dynamically populate the menu items in a Menu control.


<%@ 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)
    {
      // Create the menu structure.

      // Create the root menu item.
      MenuItem homeMenuItem = new MenuItem("Home", "Root", 
        @"Images\Home.jpg");

      // Create the submenu items.
      MenuItem musicSubMenuItem = new MenuItem("Music", "Category 1", 
        @"Images\Music.jpg");
      MenuItem moviesSubMenuItem = new MenuItem("Movies", "Category 2", 
        @"Images\Movies.jpg");

      // Add the submenu items to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem);
      homeMenuItem.ChildItems.Add(moviesSubMenuItem);

      // Add the root menu item to the Items collection 
      // of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem);
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

<%@ 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
    
      ' Create the menu structure.

      ' Create the root menu item.
      Dim homeMenuItem As New MenuItem("Home", "Root", _
        "Images\Home.jpg")

      ' Create the submenu items.
      Dim musicSubMenuItem As New MenuItem("Music", "Category 1", _
        "Images\Music.jpg")
      Dim moviesSubMenuItem As New MenuItem("Movies", "Category 2", _
        "Images\Movies.jpg")

      ' Add the submenu items to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem)
      homeMenuItem.ChildItems.Add(moviesSubMenuItem)

      ' Add the root menu item to the Items collection 
      ' of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem)
      
    End If
  
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

Remarks

Use this constructor to create a new instance of the MenuItem class using the menu text, value, and image URL specified by the text, value, and imageUrl parameters, respectively.

The following table shows initial property values for an instance of the MenuItem class.

Property Initial value
Text The value of the text parameter.
Value The value of the value parameter.
ImageUrl The value of the imageUrl parameter.

This constructor is commonly used when dynamically populating the Items collection of a Menu control or the ChildItems collection of a MenuItem object.

See also

Applies to

MenuItem(String, String, String, String)

Initializes a new instance of the MenuItem class using the specified menu text, value, image URL, and navigation URL.

public:
 MenuItem(System::String ^ text, System::String ^ value, System::String ^ imageUrl, System::String ^ navigateUrl);
public MenuItem (string text, string value, string imageUrl, string navigateUrl);
new System.Web.UI.WebControls.MenuItem : string * string * string * string -> System.Web.UI.WebControls.MenuItem
Public Sub New (text As String, value As String, imageUrl As String, navigateUrl As String)

Parameters

text
String

The text displayed for a menu item in a Menu control.

value
String

The supplemental data associated with the menu item, such as data used for handling postback events.

imageUrl
String

The URL to an image displayed next to the text in a menu item.

navigateUrl
String

The URL to link to when the menu item is clicked.

Examples

The following example demonstrates how to use this constructor to create a new instance of the MenuItem class. The MenuItem object is then used to dynamically populate the menu items in a Menu control.


<%@ 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)
    {
      // Create the menu structure.

      // Create the root menu item.
      MenuItem homeMenuItem = new MenuItem("Home", "Root",
        @"Images\Home.jpg", "Home.aspx");

      // Create the submenu items.
      MenuItem musicSubMenuItem = new MenuItem("Music", "Category 1",
        @"Images\Music.jpg", "Music.aspx");
      MenuItem moviesSubMenuItem = new MenuItem("Movies", "Category 2",
        @"Images\Movies.jpg", "Movies.aspx");

      // Add the submenu items to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem);
      homeMenuItem.ChildItems.Add(moviesSubMenuItem);

      // Add the root menu item to the Items collection 
      // of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem);
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

<%@ 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
    
      ' Create the menu structure.

      ' Create the root menu item.
      Dim homeMenuItem As New MenuItem("Home", "Root", _
        "Images\Home.jpg", "Home.aspx")

      ' Create the submenu items.
      Dim musicSubMenuItem As New MenuItem("Music", "Category 1", _
        "Images\Music.jpg", "Music.aspx")
      Dim moviesSubMenuItem As New MenuItem("Movies", "Category 2", _
        "Images\Movies.jpg", "Movies.aspx")

      ' Add the submenu items to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem)
      homeMenuItem.ChildItems.Add(moviesSubMenuItem)

      ' Add the root menu item to the Items collection 
      ' of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem)
      
    End If
  
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

Remarks

Use this constructor to create a new instance of the MenuItem class using the menu text, value, image URL, and navigation URL specified by the text, value, imageUrl, and navigateUrl parameters, respectively.

The following table shows initial property values for an instance of the MenuItem class.

Property Initial value
Text The value of the text parameter.
Value The value of the value parameter.
ImageUrl The value of the imageUrl parameter.
NavigateUrl The value of the navigateUrl parameter.

This constructor is commonly used when dynamically populating the Items collection of a Menu control or the ChildItems collection of a MenuItem object.

See also

Applies to

MenuItem(String, String, String, String, String)

Initializes a new instance of the MenuItem class using the specified menu text, value, image URL, navigation URL, and target.

public:
 MenuItem(System::String ^ text, System::String ^ value, System::String ^ imageUrl, System::String ^ navigateUrl, System::String ^ target);
public MenuItem (string text, string value, string imageUrl, string navigateUrl, string target);
new System.Web.UI.WebControls.MenuItem : string * string * string * string * string -> System.Web.UI.WebControls.MenuItem
Public Sub New (text As String, value As String, imageUrl As String, navigateUrl As String, target As String)

Parameters

text
String

The text displayed for a menu item in a Menu control.

value
String

The supplemental data associated with the menu item, such as data used for handling postback events.

imageUrl
String

The URL to an image displayed next to the text in a menu item.

navigateUrl
String

The URL to link to when the menu item is clicked.

target
String

The target window or frame in which to display the Web page content linked to a menu item when the menu item is clicked.

Examples

The following example demonstrates how to use this constructor to create a new instance of the MenuItem class. The MenuItem object is then used to dynamically populate the menu items in a Menu control.


<%@ 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)
    {
      // Create the menu structure.

      // Create the root menu item.
      MenuItem homeMenuItem = new MenuItem("Home", "Root",
        @"Images\Home.jpg", "Home.aspx", "_self");

      // Create the submenu items.
      MenuItem musicSubMenuItem = new MenuItem("Music", "Category 1",
        @"Images\Music.jpg", "Music.aspx", "_blank");
      MenuItem moviesSubMenuItem = new MenuItem("Movies", "Category 2",
        @"Images\Movies.jpg", "Movies.aspx", "_blank");

      // Add the submenu items to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem);
      homeMenuItem.ChildItems.Add(moviesSubMenuItem);

      // Add the root menu item to the Items collection 
      // of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem);
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        runat="server"/>

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

<%@ 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
    
      ' Create the menu structure.

      ' Create the root menu item.
      Dim homeMenuItem As New MenuItem("Home", "Root", _
        "Images\Home.jpg", "Home.aspx", "_self")

      ' Create the submenu items.
      Dim musicSubMenuItem As New MenuItem("Music", "Category 1", _
        "Images\Music.jpg", "Music.aspx", "_blank")
      Dim moviesSubMenuItem As New MenuItem("Movies", "Category 2", _
        "Images\Movies.jpg", "Movies.aspx", "_blank")

      ' Add the submenu items to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem)
      homeMenuItem.ChildItems.Add(moviesSubMenuItem)

      ' Add the root menu item to the Items collection 
      ' of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem)
      
    End If
  
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Constructor Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        runat="server"/>

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

Remarks

Use this constructor to create a new instance of the MenuItem class using the menu text, value, image URL, navigation URL, and target specified by the text, value, imageUrl, navigateUrl, and target parameters, respectively.

The following table shows initial property values for an instance of the MenuItem class.

Property Initial value
Text The value of the text parameter.
Value The value of the value parameter.
ImageUrl The value of the imageUrl parameter.
NavigateUrl The value of the navigateUrl parameter.
Target The value of the target parameter.

This constructor is commonly used when dynamically populating the Items collection of a Menu control or the ChildItems collection of a MenuItem object.

See also

Applies to