Expand Telerik RadTreeView (for ASP.net AJAX) on load
-
29-06-2021 - |
Question
I'm wondering why I can't find a straight way to expand all nodes of a static RadTreeView on page load. I first traversed all its properties both from properties pane of Visual Studio and also I checked it from code-behind. I didn't find any single property to tell it to open it in expanded mode. Then I looked at the Telerik's website and unfortunately I didn't find any server-side solution to make it load in expanded mode.
Do you know any ways/tricks to load it in expanded mode?
Solution 2
I found the answer (expanding from code-behind):
if (!IsPostBack)
{
foreach (RadTreeNode rtn in RTVControl.Nodes)
{
rtn.ExpandChildNodes();
rtn.Expanded = true;
}
}
OTHER TIPS
This could also help somebody. More Information here
//Javascript
var treeView = $find("<%= RadTreeView2.ClientID %>");
var nodes = treeView.get_allNodes();
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].get_nodes() != null) {
nodes[i].expand();
}
}
Protected Sub RadTreeView1_NodeCreated(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeCreated
e.Node.Expanded = True
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow