<asp:TreeView ID="TreeView1" runat="server"
ontreenodeexpanded="TreeView1_TreeNodeExpanded">
<Nodes>
<asp:TreeNode Text="Node1" Value="Node1">
<asp:TreeNode Text="Node1.1" Value="Node1.1"/>
<asp:TreeNode Text="Node1.2" Value="Node1.2"/>
<asp:TreeNode Text="Node1.3" Value="Node1.3"/>
</asp:TreeNode>
<asp:TreeNode Text="Node2" Value="Node2">
<asp:TreeNode Text="Node1.1" Value="Node2.1"/>
<asp:TreeNode Text="Node1.2" Value="Node2.2"/>
</asp:TreeNode>
<asp:TreeNode Text="Node3" Value="Node3">
<asp:TreeNode Text="Node3.1" Value="Node3.1"/>
<asp:TreeNode Text="Node3.2" Value="Node3.2"/>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
C#
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
// Loop through all nodes
foreach (TreeNode treenode in TreeView1.Nodes)
{
// If node is expanded
if (treenode != e.Node)
{
// Collapse all other nodes
treenode.Collapse();
}
}
}
VB.NET
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
' Loop through all nodes
For Each treenode As TreeNode In TreeView1.Nodes
' If node is expanded
If treenode IsNot e.Node Then
' Collapse all other nodes
treenode.Collapse()
End If
Next treenode
End Sub
Tweet
1 comment:
Thank you so much! This is what i exactly expect....
Post a Comment