RadTreeView for ASP.NET

NodeCollapse Send comments on this topic.
Telerik RadTreeView Server-Side > Server-Side Events > NodeCollapse

Glossary Item Box

The NodeCollapse event is fired upon collapsing TreeNodes (clicking the "-" icon in front of the nodes).

 

The NodeCollapse event fires only when load on demand is used - meaning only when the ExpandMode property of the respective TreeNode is set to ExpandMode.ServerSide.


The most common approach is loading nodes on demand and clearing them upon collapsing. An example is shown below:

Example:

ASPX Copy Code
<rad:RadTreeView
   
ID="RadTreeView1"
   
runat="server"
   
OnNodeCollapse="RadTreeView1_NodeCollapse"
   
OnNodeExpand="RadTreeView1_NodeExpand">
   
<Nodes>
       
<rad:RadTreeNode runat="server" ExpandMode="ServerSide" Text="New Item1">
       
</rad:RadTreeNode>
       
<rad:RadTreeNode runat="server" ExpandMode="ServerSide" Text="New Item2">
       
</rad:RadTreeNode>
   
</Nodes>
</
rad:RadTreeView>
        
C# Copy Code
protected void RadTreeView1_NodeExpand(object o, Telerik.WebControls.RadTreeNodeEventArgs e)
{
   e.NodeClicked.Nodes.Add(
new RadTreeNode("child1"));
   e.NodeClicked.Nodes.Add(
new RadTreeNode("child2"));
}
protected void RadTreeView1_NodeCollapse(object o, Telerik.WebControls.RadTreeNodeEventArgs e)
{
   e.NodeClicked.Nodes.Clear();
}
        
VB.NET Copy Code
Protected Sub RadTreeView1_NodeExpand(ByVal o As Object, ByVal e As Telerik.WebControls.RadTreeNodeEventArgs)
    e.NodeClicked.Nodes.Add(New RadTreeNode("child1"))
    e.NodeClicked.Nodes.Add(New RadTreeNode("child2"))
End Sub

Protected Sub RadTreeView1_NodeCollapse(ByVal o As Object, ByVal e As Telerik.WebControls.RadTreeNodeEventArgs)
    e.NodeClicked.Nodes.Clear
End Sub
Note: You should keep into account that the NodeCollapse event can be only applied to nodes loaded on the server-side. Therefore, you should load the nodes on the server-side (ExpandMode.ServerSide).