Menu.PathSeparator 属性
定义
public:
property char PathSeparator { char get(); void set(char value); };
public char PathSeparator { get; set; }
member this.PathSeparator : char with get, set
Public Property PathSeparator As Char
属性值
用于分隔菜单项路径的字符。The character used to delimit the path of a menu item. 默认值为斜杠 (/)。The default value is a slash mark (/).
示例
下面的代码示例演示如何使用属性将 PathSeparator 菜单项的值路径的分隔符字符更改为逗号。The following code example demonstrates how to use the PathSeparator property to change the delimiter character for a menu item's value path to a comma.
<%@ 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>
注解
(控件中的对象) 所表示的每个菜单项 MenuItem Menu 都有一个 ValuePath 属性,该属性指定菜单项的位置。Each menu item (represented by a MenuItem object) in the Menu control has a ValuePath property that specifies the position of the menu item. 值路径是一串分隔值,构成从根菜单项到当前菜单项的路径。The value path is a string of delimited values that form the path from a root menu item to the current menu item. 使用 PathSeparator 属性可以指定用于分隔菜单路径中的值的分隔字符。Use the PathSeparator property to specify the delimiting character used to separate the values in the menu path. 此值通常在分析各个值的列表时使用。This value is commonly used when parsing the list for the individual values.
根据控件中显示的文本 Menu ,分隔符字符可能需要更改以防止任何冲突。Depending on the text displayed in the Menu control, the delimiter character might need to be changed to prevent any conflicts. 例如,如果将分隔符字符设置为逗号,则显示的文本不应包含任何逗号;否则, ValuePath 属性无法准确分析。For example, if you set the delimiter character to a comma, the displayed text should not contain any commas; otherwise, the ValuePath property cannot be parsed accurately.