读书人

遍历treeView的所有子节点。该怎么解决

发布时间: 2012-01-30 21:15:58 作者: rapoo

遍历treeView的所有子节点。
我现在做的方法如下
public void GetNode(TreeNodeCollection tc)
{
foreach(TreeNode TNode in tc )
{
Response.Write(TNode.Text.ToString());
GetNode(TNode.ChildNodes);
}

}

可这样的话连根节点也列出来了,我只想输出所有叶子节点,如果做啊?
或者加个判断也行,遇到根节点就跳过。

[解决办法]
public void GetNode(TreeNodeCollection tc)
{
foreach(TreeNode TNode in tc )
{
if (TreeNode.Parent != null)
{
Response.Write(TNode.Text.ToString());
}

GetNode(TNode.ChildNodes);
}
}
[解决办法]
if(TNode.ChildNodes.Count == 0){ Response.Write(TNode.Text.ToString()); }

读书人网 >asp.net

热点推荐