Count the number of ALL child nodes and display it on the parent node

Borralis

Is it possible to count the number of child nodes of a node and display it on the parent node?

I tried this: http://www.telerik.com/help/aspnet/treeview/tree_show_child_count.html, but it only counts the number of the first level child nodes… What I need is to count all level nodes and display it next to the parent node text. Somehing like this:
-root (8)
---node_1 (4)
------node_1.1 (2)
----------node_1.1.1 (0)
----------node1.1.2 (0)
------node_1.2 (0)
---node_2 (4)
------node_2.1 (0)
------node_2.2 (1)
----------node_2.2.1 (0)
------node_2.3 (0)

Bozhidar

The Nodes property of RadTreeNode returns only the direct children of a particular node. If you want to get all of the child nodes, you can use the GetAllNodes() function.

In your case to display the number of child nodes next to the text of the node, you can use the DataBound event:

protected void RadTreeView1_DataBound(object sender, EventArgs e)

{

foreach (RadTreeNode node in RadTreeView1.GetAllNodes())

{

node.Text += " (" + node.GetAllNodes().Count.ToString() + ")";

}

}

All the best,
Bozhidar
the Telerik team

If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.