MenuItem 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 MenuItem 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| MenuItem() |
初始化一個新的類別實例 MenuItem ,沒有選單文字或值。 |
| MenuItem(String) |
使用指定的選單文字初始化該類別的新實例 MenuItem 。 |
| MenuItem(String, String) |
使用指定的選單文字與值初始化類別的新實例 MenuItem 。 |
| MenuItem(String, String, String) |
利用指定的選單文字、值和圖片的網址初始化該類別的新實例 MenuItem 。 |
| MenuItem(String, String, String, String) |
使用指定的選單文字、值、圖片網址及導航網址初始化該類別的新實例 MenuItem 。 |
| MenuItem(String, String, String, String, String) |
使用指定的選單文字、值、圖片 URL、導航 URL 及目標,初始化該類別的新 MenuItem 實例。 |
MenuItem()
初始化一個新的類別實例 MenuItem ,沒有選單文字或值。
public:
MenuItem();
public MenuItem();
Public Sub New ()
範例
以下範例示範如何使用此建構子建立新的類別實例 MenuItem 。 接著,這個 MenuItem 物件會被用來動態地填充控制項中的 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>
備註
使用此建構器建立一個沒有選單文字或值的新類別實例 MenuItem 。
Note
使用此建構子時,物件中 MenuItem 的所有屬性皆設為預設值。 建立物件後,務必依需求設定屬性。
此建構子常用於動態填充 Items 控制項的集合 Menu 或 ChildItems 物件的集合 MenuItem 。
另請參閱
適用於
MenuItem(String)
使用指定的選單文字初始化該類別的新實例 MenuItem 。
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)
參數
範例
以下範例示範如何使用此建構子建立新的類別實例 MenuItem 。 接著,這個 MenuItem 物件會被用來動態地填充控制項中的 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>
備註
使用此建構子,利用參數指定的MenuItem選單文字建立新的類別實例text。
下表顯示該 MenuItem 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Text | 文字參數的值。 |
此建構子常用於動態填充 Items 控制項的集合 Menu 或 ChildItems 物件的集合 MenuItem 。
另請參閱
適用於
MenuItem(String, String)
使用指定的選單文字與值初始化類別的新實例 MenuItem 。
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)
參數
- value
- String
與選單項目相關的補充資料,例如用於處理回傳事件的資料。
範例
以下範例示範如何使用此建構子建立新的類別實例 MenuItem 。 接著,這個 MenuItem 物件會被用來動態地填充控制項中的 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>
備註
使用這個建構子,分別使用選MenuItem單文字和參數指定的text值來建立該類別的新value實例。
下表顯示該 MenuItem 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Text | 參數的 text 值。 |
| Value | 參數的 value 值。 |
此建構子常用於動態填充 Items 控制項的集合 Menu 或 ChildItems 物件的集合 MenuItem 。
另請參閱
適用於
MenuItem(String, String, String)
利用指定的選單文字、值和圖片的網址初始化該類別的新實例 MenuItem 。
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)
參數
- value
- String
與選單項目相關的補充資料,例如用於處理回傳事件的資料。
- imageUrl
- String
選單項目中顯示在文字旁的圖片網址。
範例
以下範例示範如何使用此建構子建立新的類別實例 MenuItem 。 接著,這個 MenuItem 物件會被用來動態地填充控制項中的 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>
備註
使用此建構器,利用選單文字、值與圖片 URL 分別由 MenuItem、 和 textvalue參數指定,建立新的類別實例imageUrl。
下表顯示該 MenuItem 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Text | 參數的 text 值。 |
| Value | 參數的 value 值。 |
| ImageUrl | 參數的 imageUrl 值。 |
此建構子常用於動態填充 Items 控制項的集合 Menu 或 ChildItems 物件的集合 MenuItem 。
另請參閱
適用於
MenuItem(String, String, String, String)
使用指定的選單文字、值、圖片網址及導航網址初始化該類別的新實例 MenuItem 。
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)
參數
- value
- String
與選單項目相關的補充資料,例如用於處理回傳事件的資料。
- imageUrl
- String
選單項目中顯示在文字旁的圖片網址。
- navigateUrl
- String
點擊選單項目時要連結的網址。
範例
以下範例示範如何使用此建構子建立新的類別實例 MenuItem 。 接著,這個 MenuItem 物件會被用來動態地填充控制項中的 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>
備註
使用此建構子,利用選單文字、值、圖片 URL 及導航 URL 分別由 MenuItem、 、 textvalueimageUrl和 參數指定,建立新的類別實例。navigateUrl
下表顯示該 MenuItem 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Text | 參數的 text 值。 |
| Value | 參數的 value 值。 |
| ImageUrl | 參數的 imageUrl 值。 |
| NavigateUrl | 參數的 navigateUrl 值。 |
此建構子常用於動態填充 Items 控制項的集合 Menu 或 ChildItems 物件的集合 MenuItem 。
另請參閱
適用於
MenuItem(String, String, String, String, String)
使用指定的選單文字、值、圖片 URL、導航 URL 及目標,初始化該類別的新 MenuItem 實例。
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)
參數
- value
- String
與選單項目相關的補充資料,例如用於處理回傳事件的資料。
- imageUrl
- String
選單項目中顯示在文字旁的圖片網址。
- navigateUrl
- String
點擊選單項目時要連結的網址。
- target
- String
點擊選單項目時,顯示網頁內容的目標視窗或框架,該視窗與該選單項目連結。
範例
以下範例示範如何使用此建構子建立新的類別實例 MenuItem 。 接著,這個 MenuItem 物件會被用來動態地填充控制項中的 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>
備註
使用此建構子,利用選單文字、值、圖片網址、導航網址與目標,分別由 MenuItem、 text、 valueimageUrlnavigateUrl 、 和 參數指定,建立新的類別實例。target
下表顯示該 MenuItem 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Text | 參數的 text 值。 |
| Value | 參數的 value 值。 |
| ImageUrl | 參數的 imageUrl 值。 |
| NavigateUrl | 參數的 navigateUrl 值。 |
| Target | 參數的 target 值。 |
此建構子常用於動態填充 Items 控制項的集合 Menu 或 ChildItems 物件的集合 MenuItem 。