且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在TreeView控件隐藏节点

更新时间:2023-10-13 14:23:16

我使用Telerik的RadTreeView;树视图不具有为每个节点DataBound事件和可见性属性。这里是code删除的子节点的TreeView。

I use Telerik RadTreeView; TreeView doesn't have DataBound event and Visible property for each node. Here is the code to remove the child node for TreeView.

protected void Page_Load(object sender, EventArgs e)
{
  RemoveNodeRecurrently(TreeView1.Nodes, "Status");
}

private void RemoveNodeRecurrently(TreeNodeCollection childNodeCollection, string text)
{
  foreach (TreeNode childNode in childNodeCollection)
  {
    if (childNode.ChildNodes.Count > 0)
      RemoveNodeRecurrently(childNode.ChildNodes, text);

    if (childNode.Text == text)
    {
      TreeNode parentNode = childNode.Parent;
      parentNode.ChildNodes.Remove(childNode);
      break;
    }
  }
}