MenuItem Konstruktory
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Inicjuje nowe wystąpienie klasy MenuItem.
Przeciążenia
| Nazwa | Opis |
|---|---|
| MenuItem() |
Inicjuje MenuItem nowe wystąpienie klasy bez tekstu menu lub wartości. |
| MenuItem(String) |
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu. |
| MenuItem(String, String) |
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu i wartości menu. |
| MenuItem(String, String, String) |
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu, wartości i adresu URL obrazu. |
| MenuItem(String, String, String, String) |
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu, wartości, adresu URL obrazu i adresu URL nawigacji. |
| MenuItem(String, String, String, String, String) |
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu, wartości, adresu URL obrazu, adresu URL nawigacji i elementu docelowego. |
MenuItem()
Inicjuje MenuItem nowe wystąpienie klasy bez tekstu menu lub wartości.
public:
MenuItem();
public MenuItem();
Public Sub New ()
Przykłady
W poniższym przykładzie pokazano, jak za pomocą tego konstruktora utworzyć nowe wystąpienie MenuItem klasy. Następnie MenuItem obiekt jest używany do dynamicznego wypełniania elementów menu w kontrolce Menu .
<%@ 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>
Uwagi
Użyj tego konstruktora, aby utworzyć nowe wystąpienie MenuItem klasy bez tekstu menu lub wartości.
Note
Gdy ten konstruktor jest używany, wszystkie właściwości w MenuItem obiekcie są ustawione na ich wartości domyślne. Pamiętaj, aby ustawić właściwości, zgodnie z potrzebami, po utworzeniu obiektu.
Ten konstruktor jest często używany podczas dynamicznego wypełniania Items kolekcji kontrolki Menu lub ChildItems kolekcji MenuItem obiektu.
Zobacz też
Dotyczy
MenuItem(String)
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu.
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)
Parametry
Przykłady
W poniższym przykładzie pokazano, jak za pomocą tego konstruktora utworzyć nowe wystąpienie MenuItem klasy. Następnie MenuItem obiekt jest używany do dynamicznego wypełniania elementów menu w kontrolce Menu .
<%@ 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>
Uwagi
Użyj tego konstruktora, aby utworzyć nowe wystąpienie MenuItem klasy przy użyciu tekstu menu określonego text przez parametr .
W poniższej tabeli przedstawiono początkową wartość właściwości dla wystąpienia MenuItem klasy.
| Majątek | Wartość początkowa |
|---|---|
| Text | Wartość parametru tekstowego. |
Ten konstruktor jest często używany podczas dynamicznego wypełniania Items kolekcji kontrolki Menu lub ChildItems kolekcji MenuItem obiektu.
Zobacz też
Dotyczy
MenuItem(String, String)
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu i wartości menu.
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)
Parametry
- value
- String
Dane uzupełniające skojarzone z elementem menu, takie jak dane używane do obsługi zdarzeń ogłaszania zwrotnego.
Przykłady
W poniższym przykładzie pokazano, jak za pomocą tego konstruktora utworzyć nowe wystąpienie MenuItem klasy. Następnie MenuItem obiekt jest używany do dynamicznego wypełniania elementów menu w kontrolce Menu .
<%@ 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>
Uwagi
Użyj tego konstruktora, aby utworzyć nowe wystąpienie MenuItem klasy przy użyciu tekstu menu i wartości określonej odpowiednio przez text parametry i value .
W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia MenuItem klasy.
| Majątek | Wartość początkowa |
|---|---|
| Text | Wartość parametru text . |
| Value | Wartość parametru value . |
Ten konstruktor jest często używany podczas dynamicznego wypełniania Items kolekcji kontrolki Menu lub ChildItems kolekcji MenuItem obiektu.
Zobacz też
Dotyczy
MenuItem(String, String, String)
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu, wartości i adresu URL obrazu.
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)
Parametry
- value
- String
Dane uzupełniające skojarzone z elementem menu, takie jak dane używane do obsługi zdarzeń ogłaszania zwrotnego.
- imageUrl
- String
Adres URL obrazu wyświetlanego obok tekstu w elemencie menu.
Przykłady
W poniższym przykładzie pokazano, jak za pomocą tego konstruktora utworzyć nowe wystąpienie MenuItem klasy. Następnie MenuItem obiekt jest używany do dynamicznego wypełniania elementów menu w kontrolce Menu .
<%@ 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>
Uwagi
Użyj tego konstruktora, aby utworzyć nowe wystąpienie MenuItem klasy przy użyciu tekstu menu, wartości i adresu URL obrazu określonego textodpowiednio przez parametry , valuei imageUrl .
W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia MenuItem klasy.
| Majątek | Wartość początkowa |
|---|---|
| Text | Wartość parametru text . |
| Value | Wartość parametru value . |
| ImageUrl | Wartość parametru imageUrl . |
Ten konstruktor jest często używany podczas dynamicznego wypełniania Items kolekcji kontrolki Menu lub ChildItems kolekcji MenuItem obiektu.
Zobacz też
Dotyczy
MenuItem(String, String, String, String)
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu, wartości, adresu URL obrazu i adresu URL nawigacji.
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)
Parametry
- value
- String
Dane uzupełniające skojarzone z elementem menu, takie jak dane używane do obsługi zdarzeń ogłaszania zwrotnego.
- imageUrl
- String
Adres URL obrazu wyświetlanego obok tekstu w elemencie menu.
- navigateUrl
- String
Adres URL do linku po kliknięciu elementu menu.
Przykłady
W poniższym przykładzie pokazano, jak za pomocą tego konstruktora utworzyć nowe wystąpienie MenuItem klasy. Następnie MenuItem obiekt jest używany do dynamicznego wypełniania elementów menu w kontrolce Menu .
<%@ 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>
Uwagi
Użyj tego konstruktora, aby utworzyć nowe wystąpienie MenuItem klasy przy użyciu tekstu menu, wartości, adresu URL obrazu i adresu URL nawigacji określonego textodpowiednio przez parametry , value, imageUrli navigateUrl .
W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia MenuItem klasy.
| Majątek | Wartość początkowa |
|---|---|
| Text | Wartość parametru text . |
| Value | Wartość parametru value . |
| ImageUrl | Wartość parametru imageUrl . |
| NavigateUrl | Wartość parametru navigateUrl . |
Ten konstruktor jest często używany podczas dynamicznego wypełniania Items kolekcji kontrolki Menu lub ChildItems kolekcji MenuItem obiektu.
Zobacz też
Dotyczy
MenuItem(String, String, String, String, String)
Inicjuje nowe wystąpienie MenuItem klasy przy użyciu określonego tekstu menu, wartości, adresu URL obrazu, adresu URL nawigacji i elementu docelowego.
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)
Parametry
- value
- String
Dane uzupełniające skojarzone z elementem menu, takie jak dane używane do obsługi zdarzeń ogłaszania zwrotnego.
- imageUrl
- String
Adres URL obrazu wyświetlanego obok tekstu w elemencie menu.
- navigateUrl
- String
Adres URL do linku po kliknięciu elementu menu.
- target
- String
Okno docelowe lub ramka, w której ma być wyświetlana zawartość strony sieci Web połączona z elementem menu po kliknięciu elementu menu.
Przykłady
W poniższym przykładzie pokazano, jak za pomocą tego konstruktora utworzyć nowe wystąpienie MenuItem klasy. Następnie MenuItem obiekt jest używany do dynamicznego wypełniania elementów menu w kontrolce Menu .
<%@ 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>
Uwagi
Użyj tego konstruktora, aby utworzyć nowe wystąpienie MenuItem klasy przy użyciu tekstu menu, wartości, adresu URL obrazu, adresu URL nawigacji i obiektu docelowego określonego textodpowiednio przez parametry , , valueimageUrl, navigateUrli target .
W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia MenuItem klasy.
| Majątek | Wartość początkowa |
|---|---|
| Text | Wartość parametru text . |
| Value | Wartość parametru value . |
| ImageUrl | Wartość parametru imageUrl . |
| NavigateUrl | Wartość parametru navigateUrl . |
| Target | Wartość parametru target . |
Ten konstruktor jest często używany podczas dynamicznego wypełniania Items kolekcji kontrolki Menu lub ChildItems kolekcji MenuItem obiektu.