日期:2014-05-20  浏览次数:20561 次

遍历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()); }