Menu.FindItem(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取位於指定值路徑的功能表項目。
public:
System::Web::UI::WebControls::MenuItem ^ FindItem(System::String ^ valuePath);
public System.Web.UI.WebControls.MenuItem FindItem (string valuePath);
member this.FindItem : string -> System.Web.UI.WebControls.MenuItem
Public Function FindItem (valuePath As String) As MenuItem
參數
- valuePath
- String
要擷取之功能表項目的值路徑。
傳回
MenuItem,代表位於指定值路徑的功能表項目。
範例
下列程式碼範例示範如何使用 FindItem 方法,從位於指定值路徑的 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)
{
// The value path for a menu item is a delimited list
// of menu text values that form a path from the root
// menu item to the current menu item.
// Declare the value path to the Classical menu item using
// the delimiter character specified in the PathSeparator
// property. In this example, the delimiter character is a
// comma.
String valuePath = "Home,Music,Classical";
// Use the FindItem method to get the Classical menu item using
// its value path.
MenuItem item = NavigationMenu.FindItem(valuePath);
// Indicate whether the menu item was found.
if (item != null)
{
Message.Text = item.Text + " menu item found at depth " +
item.Depth.ToString() + ".";
}
else
{
Message.Text = "Menu item not found.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu PathSeparator and FindItem Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu PathSeparator and FindItem Example</h3>
<!-- Use the PathSeparator property to -->
<!-- change the delimiter character for -->
<!-- the value path of a menu item to a -->
<!-- comma (,). -->
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
pathseparator=","
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
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)
' The value path for a menu item is a delimited list
' of menu text values that form a path from the root
' menu item to the current menu item.
' Declare the value path to the Classical menu item using
' the delimiter character specified in the PathSeparator
' property. In this example, the delimiter character is a
' comma.
Dim valuePath As String = "Home,Music,Classical"
' Use the FindItem method to get the Classical menu item using
' its value path.
Dim item As MenuItem = NavigationMenu.FindItem(valuePath)
' Indicate whether the menu item was found.
If Not item Is Nothing Then
Message.Text = item.Text & " menu item found at depth " & _
item.Depth.ToString() & "."
Else
Message.Text = "Menu item not found."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu PathSeparator and FindItem Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu PathSeparator and FindItem Example</h3>
<!-- Use the PathSeparator property to -->
<!-- change the delimiter character for -->
<!-- the value path of a menu item to a -->
<!-- comma (,). -->
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
pathseparator=","
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
備註
FindItem使用 方法從 控制項擷 Menu 取 MenuItem 物件。 若要擷 MenuItem 取物件,您必須指定功能表項目的功能表路徑。 功能表路徑是分隔值的字串,可形成從根功能表項目到目前功能表項目的路徑。 若要判斷分隔符號,請使用 PathSeparator 屬性。