TreeView 折叠所有

前台代码:
<asp:TreeView ID="TreeView1" runat="server" ExpandDepth="0" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded" ShowLines="True">
要害是:OnTreeNodeExpanded="TreeView1_TreeNodeExpanded"

后台代码:

  protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
            TreeNodeCollection ts = null;
            if (e.Node.Parent == null)
            {
                ts = ((TreeView)sender).Nodes;
            }
            else
                ts = e.Node.Parent.ChildNodes;
            foreach (TreeNode node in ts)
            {
                if (node != e.Node)
                {
                    node.Collapse();
                }
            }
        }
 
 
 

 

posted on 2014-08-16 15:40  Haustbule  阅读(339)  评论(0编辑  收藏  举报