MenuItem Costruttori

Definizione

Inizializza una nuova istanza della classe MenuItem.

Overload

Nome Descrizione
MenuItem()

Inizializza una nuova istanza della MenuItem classe senza testo di menu o un valore.

MenuItem(String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo del menu specificato.

MenuItem(String, String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo e il valore del menu specificati.

MenuItem(String, String, String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo, il valore e l'URL del menu specificati per un'immagine.

MenuItem(String, String, String, String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo del menu, il valore, l'URL dell'immagine e l'URL di spostamento specificati.

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

Inizializza una nuova istanza della MenuItem classe utilizzando il testo del menu, il valore, l'URL dell'immagine, l'URL di spostamento e la destinazione specificati.

MenuItem()

Inizializza una nuova istanza della MenuItem classe senza testo di menu o un valore.

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

Esempio

Nell'esempio seguente viene illustrato come usare questo costruttore per creare una nuova istanza della MenuItem classe . L'oggetto MenuItem viene quindi utilizzato per popolare dinamicamente le voci di menu in un Menu controllo .


<%@ 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>

Commenti

Utilizzare questo costruttore per creare una nuova istanza di una MenuItem classe senza testo di menu o un valore.

Note

Quando viene usato questo costruttore, tutte le proprietà dell'oggetto MenuItem vengono impostate sui valori predefiniti. Assicurarsi di impostare le proprietà, se necessario, dopo aver creato l'oggetto .

Questo costruttore viene comunemente usato quando si popola in modo dinamico la Items raccolta di un Menu controllo o della ChildItems raccolta di un MenuItem oggetto .

Vedi anche

Si applica a

MenuItem(String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo del menu specificato.

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)

Parametri

text
String

Testo visualizzato per una voce di menu in un Menu controllo .

Esempio

Nell'esempio seguente viene illustrato come usare questo costruttore per creare una nuova istanza della MenuItem classe . L'oggetto MenuItem viene quindi utilizzato per popolare dinamicamente le voci di menu in un Menu controllo .


<%@ 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>

Commenti

Utilizzare questo costruttore per creare una nuova istanza della MenuItem classe usando il testo del menu specificato dal text parametro .

Nella tabella seguente viene illustrato il valore della proprietà iniziale per un'istanza della MenuItem classe .

Proprietà Valore iniziale
Text Valore del parametro di testo.

Questo costruttore viene comunemente usato quando si popola in modo dinamico la Items raccolta di un Menu controllo o della ChildItems raccolta di un MenuItem oggetto .

Vedi anche

Si applica a

MenuItem(String, String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo e il valore del menu specificati.

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)

Parametri

text
String

Testo visualizzato per una voce di menu in un Menu controllo .

value
String

Dati supplementari associati alla voce di menu, ad esempio i dati usati per la gestione degli eventi di postback.

Esempio

Nell'esempio seguente viene illustrato come usare questo costruttore per creare una nuova istanza della MenuItem classe . L'oggetto MenuItem viene quindi utilizzato per popolare dinamicamente le voci di menu in un Menu controllo .


<%@ 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>

Commenti

Utilizzare questo costruttore per creare una nuova istanza della MenuItem classe usando rispettivamente il testo e il valore del text menu specificati dai parametri e value .

Nella tabella seguente vengono illustrati i valori iniziali delle proprietà per un'istanza della MenuItem classe .

Proprietà Valore iniziale
Text Valore del text parametro .
Value Valore del value parametro .

Questo costruttore viene comunemente usato quando si popola in modo dinamico la Items raccolta di un Menu controllo o della ChildItems raccolta di un MenuItem oggetto .

Vedi anche

Si applica a

MenuItem(String, String, String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo, il valore e l'URL del menu specificati per un'immagine.

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)

Parametri

text
String

Testo visualizzato per una voce di menu in un Menu controllo .

value
String

Dati supplementari associati alla voce di menu, ad esempio i dati usati per la gestione degli eventi di postback.

imageUrl
String

URL di un'immagine visualizzata accanto al testo in una voce di menu.

Esempio

Nell'esempio seguente viene illustrato come usare questo costruttore per creare una nuova istanza della MenuItem classe . L'oggetto MenuItem viene quindi utilizzato per popolare dinamicamente le voci di menu in un Menu controllo .


<%@ 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>

Commenti

Usare questo costruttore per creare una nuova istanza della MenuItem classe usando rispettivamente il testo del menu, il valore e l'URL dell'immagine specificati dai textparametri , valuee imageUrl .

Nella tabella seguente vengono illustrati i valori iniziali delle proprietà per un'istanza della MenuItem classe .

Proprietà Valore iniziale
Text Valore del text parametro .
Value Valore del value parametro .
ImageUrl Valore del imageUrl parametro .

Questo costruttore viene comunemente usato quando si popola in modo dinamico la Items raccolta di un Menu controllo o della ChildItems raccolta di un MenuItem oggetto .

Vedi anche

Si applica a

MenuItem(String, String, String, String)

Inizializza una nuova istanza della MenuItem classe utilizzando il testo del menu, il valore, l'URL dell'immagine e l'URL di spostamento specificati.

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)

Parametri

text
String

Testo visualizzato per una voce di menu in un Menu controllo .

value
String

Dati supplementari associati alla voce di menu, ad esempio i dati usati per la gestione degli eventi di postback.

imageUrl
String

URL di un'immagine visualizzata accanto al testo in una voce di menu.

navigateUrl
String

URL a cui collegarsi quando si fa clic sulla voce di menu.

Esempio

Nell'esempio seguente viene illustrato come usare questo costruttore per creare una nuova istanza della MenuItem classe . L'oggetto MenuItem viene quindi utilizzato per popolare dinamicamente le voci di menu in un Menu controllo .


<%@ 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>

Commenti

Usare questo costruttore per creare una nuova istanza della MenuItem classe usando rispettivamente il testo del menu, il valore, l'URL dell'immagine e l'URL textdi spostamento specificati dai parametri , valueimageUrl, e navigateUrl .

Nella tabella seguente vengono illustrati i valori iniziali delle proprietà per un'istanza della MenuItem classe .

Proprietà Valore iniziale
Text Valore del text parametro .
Value Valore del value parametro .
ImageUrl Valore del imageUrl parametro .
NavigateUrl Valore del navigateUrl parametro .

Questo costruttore viene comunemente usato quando si popola in modo dinamico la Items raccolta di un Menu controllo o della ChildItems raccolta di un MenuItem oggetto .

Vedi anche

Si applica a

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

Inizializza una nuova istanza della MenuItem classe utilizzando il testo del menu, il valore, l'URL dell'immagine, l'URL di spostamento e la destinazione specificati.

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)

Parametri

text
String

Testo visualizzato per una voce di menu in un Menu controllo .

value
String

Dati supplementari associati alla voce di menu, ad esempio i dati usati per la gestione degli eventi di postback.

imageUrl
String

URL di un'immagine visualizzata accanto al testo in una voce di menu.

navigateUrl
String

URL a cui collegarsi quando si fa clic sulla voce di menu.

target
String

Finestra o frame di destinazione in cui visualizzare il contenuto della pagina Web collegato a una voce di menu quando si fa clic sulla voce di menu.

Esempio

Nell'esempio seguente viene illustrato come usare questo costruttore per creare una nuova istanza della MenuItem classe . L'oggetto MenuItem viene quindi utilizzato per popolare dinamicamente le voci di menu in un Menu controllo .


<%@ 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>

Commenti

Usare questo costruttore per creare una nuova istanza della MenuItem classe usando rispettivamente il testo del menu, il valore, l'URL dell'immagine, l'URL di spostamento e la textdestinazione specificati dai parametri , valueimageUrl, navigateUrl, e target .

Nella tabella seguente vengono illustrati i valori iniziali delle proprietà per un'istanza della MenuItem classe .

Proprietà Valore iniziale
Text Valore del text parametro .
Value Valore del value parametro .
ImageUrl Valore del imageUrl parametro .
NavigateUrl Valore del navigateUrl parametro .
Target Valore del target parametro .

Questo costruttore viene comunemente usato quando si popola in modo dinamico la Items raccolta di un Menu controllo o della ChildItems raccolta di un MenuItem oggetto .

Vedi anche

Si applica a