TreeView.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
属性值
用于分隔在 ValuePath 属性中指定的节点值的字符。The character used to delimit the node values specified in the ValuePath property. 默认值为斜杠 (/)。The default is a slash mark (/).
示例
下面的代码示例演示如何使用 PathSeparator 属性来指定节点的属性的分隔符字符 ValuePath 。The following code example demonstrates how to use the PathSeparator property to specify the delimiter character for the ValuePath property of a node. 此值随后用于分析 ValuePath 各个值的属性。This value is then used to parse the ValuePath property for the individual values.
<%@ 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 Index_Changed(Object sender, EventArgs e)
{
// Set the PathSeparator character based on the user's selection.
// Notice that the value must be converted to a Char data type.
BookTreeView.PathSeparator = Convert.ToChar(List.SelectedItem.Text);
// Display the ValuePath values for the second-level nodes.
Message.Text = "The ValuePath values for the second-level nodes are:<br />";
foreach(TreeNode node in BookTreeView.Nodes[0].ChildNodes)
{
// Create the delimiter array with the PathSeparator value for the Split method.
Char[] DelimiterArray = new Char[1];
DelimiterArray[0] = BookTreeView.PathSeparator;
// Parse the ValuePath value using the delimiter array.
String[] NodeValues = node.ValuePath.Split(DelimiterArray);
// Display the node values.
for(int i=0; i<NodeValues.Length; i++)
{
if(i != NodeValues.Length - 1)
{
// Append the delimiter character.
Message.Text += NodeValues[i] + BookTreeView.PathSeparator.ToString();
}
else
{
// Do not append the delimiter character.
Message.Text += NodeValues[i];
}
}
// Append a line break for the next node.
Message.Text += "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeView PathSeparator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeView PathSeparator Example</h3>
<asp:TreeView id="BookTreeView"
ExpandDepth="-1"
PathSeparator="/"
runat="server">
<Nodes>
<asp:TreeNode Value="Chapter 1"
Text="Chapter 1">
<asp:TreeNode Value="Section 1"
Text="Section 1">
<asp:TreeNode Value="Paragraph 1"
Text="Paragraph 1">
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Value="Section 2"
Text="Section 2">
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<br />
<asp:Label id="Message" runat="server"/>
<hr />
Select a path separator value:<br />
<asp:DropDownList ID="List"
AutoPostBack="true"
OnSelectedIndexChanged="Index_Changed"
runat="server">
<asp:ListItem Selected="true">/</asp:ListItem>
<asp:ListItem>\</asp:ListItem>
<asp:ListItem>|</asp:ListItem>
<asp:ListItem>,</asp:ListItem>
<asp:ListItem>;</asp:ListItem>
</asp:DropDownList>
</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 Index_Changed(ByVal sender As Object, ByVal e As EventArgs)
' Set the PathSeparator character based on the user's selection.
' Notice that the value must be converted to a Char data type.
BookTreeView.PathSeparator = Convert.ToChar(List.SelectedItem.Text)
' Display the ValuePath values for the second-level nodes.
Message.Text = "The ValuePath values for the second-level nodes are:<br />"
Dim node As TreeNode
For Each node In BookTreeView.Nodes(0).ChildNodes
' Create the delimiter array with the PathSeparator value for the Split method.
Dim DelimiterArray(1) As Char
DelimiterArray(0) = BookTreeView.PathSeparator
' Parse the ValuePath value using the delimiter array.
Dim NodeValues() As String = node.ValuePath.Split(DelimiterArray)
' Display the node values.
Dim i As Integer
For i = 0 To NodeValues.Length - 1
If i <> NodeValues.Length - 1 Then
' Append the delimiter character.
Message.Text &= NodeValues(i) & BookTreeView.PathSeparator.ToString()
Else
' Do not append the delimiter character.
Message.Text &= NodeValues(i)
End If
Next
' Append a line break for the next node.
Message.Text &= "<br />"
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeView PathSeparator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeView PathSeparator Example</h3>
<asp:TreeView id="BookTreeView"
ExpandDepth="-1"
PathSeparator="/"
runat="server">
<Nodes>
<asp:TreeNode Value="Chapter 1"
Text="Chapter 1">
<asp:TreeNode Value="Section 1"
Text="Section 1">
<asp:TreeNode Value="Paragraph 1"
Text="Paragraph 1">
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Value="Section 2"
Text="Section 2">
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<br />
<asp:Label id="Message" runat="server"/>
<hr />
Select a path separator value:<br />
<asp:DropDownList ID="List"
AutoPostBack="true"
OnSelectedIndexChanged="Index_Changed"
runat="server">
<asp:ListItem Selected="true">/</asp:ListItem>
<asp:ListItem>\</asp:ListItem>
<asp:ListItem>|</asp:ListItem>
<asp:ListItem>,</asp:ListItem>
<asp:ListItem>;</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
注解
ValuePath属性包含以分隔符分隔的节点值列表,这些值构成从根节点到当前节点的路径。The ValuePath property contains a delimiter-separated list of node values that form a path from the root node to the current node. 使用 PathSeparator 属性指定分隔节点值时所用的分隔符字符。Use the PathSeparator property to specify the delimiter character that is used to separate the node values. 此值通常在分析各个值的列表时使用。This value is commonly used when parsing the list for the individual values.
根据控件中显示的文本 TreeView ,分隔符字符可能需要更改以防止任何冲突。Depending on the text that is displayed in the TreeView 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.
此属性的值存储在视图状态中。The value of this property is stored in view state.