山谷 - 2008-1-14 16:21:00
<%@ Page Language="VB" %>
<SCRIPT runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' If the TreeView control contains any root nodes, perform a
' preorder traversal of the tree and display the text of each node.
If LinksTreeView.Nodes.Count > 0 Then
' Iterate through the root nodes in the Nodes property.
Dim i As Integer
For i = 0 To LinksTreeView.Nodes.Count - 1
' Display the nodes.
DisplayChildNodeText(LinksTreeView.Nodes(i))
Next i
Else
Message.Text = "The TreeView control does not have any nodes."
End If
End Sub
Sub DisplayChildNodeText(ByVal node As TreeNode)
' Display the node's text value.
Message.Text &= node.Text & "<br>"
' Iterate through the child nodes of the parent node passed into
' this method and display their values.
Dim i As Integer
For i = 0 To node.ChildNodes.Count - 1
' Recursively call the DisplayChildNodeText method to
' traverse the tree and display all the child nodes.
DisplayChildNodeText(node.ChildNodes(i))
Next i
End Sub
</SCRIPT>
<HTML>
<FORM runat="server">
<H3>TreeNodeCollection Count Example</H3>
<ASP:TREEVIEW id=LinksTreeView runat="server" ForeColor="Blue" Font-Name="Arial">
<LEVELSTYLES>
<ASP:TREENODESTYLE ForeColor="DarkGreen" Font-Size="12pt" Font-Bold="true" ChildNodesPadding="10" />
<ASP:TREENODESTYLE Font-Size="10pt" Font-Bold="true" ChildNodesPadding="5" />
<ASP:TREENODESTYLE Font-Size="10pt" ChildNodesPadding="5" Font-UnderLine="true" />
<ASP:TREENODESTYLE Font-Size="8pt" ChildNodesPadding="10" />
</LEVELSTYLES>
<NODES>
<ASP:TREENODE Text="Table of Contents" Expanded="true">
<ASP:TREENODE Text="Chapter One">
<ASP:TREENODE Text="Section 1.0">
<ASP:TREENODE Text="Topic 1.0.1" />
<ASP:TREENODE Text="Topic 1.0.2" />
<ASP:TREENODE Text="Topic 1.0.3" />
</ASP:TREENODE>
<ASP:TREENODE Text="Section 1.1">
<ASP:TREENODE Text="Topic 1.1.1" />
<ASP:TREENODE Text="Topic 1.1.2" />
<ASP:TREENODE Text="Topic 1.1.3" />
<ASP:TREENODE Text="Topic 1.1.4" />
</ASP:TREENODE>
</ASP:TREENODE>
<ASP:TREENODE Text="Chapter Two">
<ASP:TREENODE Text="Section 2.0">
<ASP:TREENODE Text="Topic 2.0.1">
<ASP:TREENODE Text="Subtopic 1" />
<ASP:TREENODE Text="Subtopic 2" />
</ASP:TREENODE>
<ASP:TREENODE Text="Topic 2.0.2" />
</ASP:TREENODE>
</ASP:TREENODE>
</ASP:TREENODE>
<ASP:TREENODE Text="Appendix A" />
<ASP:TREENODE Text="Appendix B" />
<ASP:TREENODE Text="Appendix C" />
</NODES>
</ASP:TREEVIEW>
<BR><BR>
<ASP:LABEL id=Message runat="server" />
</FORM>