treeview展开一个节点就关闭其他节点
1 前台代码:
2 <asp:TreeView ID="TreeView1" runat="server" ExpandDepth="0" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded" ShowLines="True">
3 要害是:OnTreeNodeExpanded="TreeView1_TreeNodeExpanded"
4
5 后台代码:
6
7 protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
8 {
9 TreeNodeCollection ts = null;
10 if (e.Node.Parent == null)
11 {
12 ts = ((TreeView)sender).Nodes;
13 }
14 else
15 ts = e.Node.Parent.ChildNodes;
16 foreach (TreeNode node in ts)
17 {
18 if (node != e.Node)
19 {
20 node.Collapse();
21 }
22 }
23 }
24 -