This is a migrated thread and some comments may be shown as answers.

ExpandDepth equivilent?

3 Answers 86 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 20 Mar 2008, 02:55 PM
I'm creating a treeview via a database. Currently, only the root node is displayed when the page loads. Is there an equivilent to the Microsoft Treeview ExpandDepth so that I can display the first level underneath the root as well?

I tried expanding root node in the code behind without success. Here is my code:

<telerik:RadTreeView ID="RadTreeView1" runat="server" DataSourceID="DataMart" DataFieldID="cellkey" 
    DataFieldParentID="cellparent" DataTextField="celldescriptor"   
    LoadingStatusPosition="BeforeNodeText" SingleExpandPath="True">  
    <CollapseAnimation Duration="100" Type="None" /> 
    <ExpandAnimation Duration="100" Type="None" />      
</telerik:RadTreeView> 
<asp:SqlDataSource ID="DataMart" runat="server" ConnectionString="<%$ ConnectionStrings:DataMart %>" 
    SelectCommand="SST.PR_GET_JUPITER_TREE" SelectCommandType="StoredProcedure">  
    <SelectParameters> 
        <asp:Parameter DefaultValue="2" Name="Starting_Node" Type="Int32" /> 
    </SelectParameters> 
</asp:SqlDataSource> 

Thanks!

3 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 24 Mar 2008, 10:20 AM
Hello Paul,

I guess you are calling the expand method before the TreeView is databound.

There are two ways to proceed:

1. Subscribe to the NodeBound event handler and set the Expanded property for the root nodes. Here is how:

protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e) 
    //root nodes only 
    if (e.Node.Level == 0) 
    { 
        e.Node.Expanded = true
    } 

2. Manually call the DataBind() method and then enumerate the root nodes and expand them:

protected void Page_Load(object sender, EventArgs e) 
    RadTreeView1.DataBind(); 
    //enumerate the root nodes 
    foreach (RadTreeNode rootNode in RadTreeView1.Nodes) 
    { 
        rootNode.Expanded = true
    } 

I hope this helps.

All the best,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Paul
Top achievements
Rank 1
answered on 24 Mar 2008, 01:35 PM
Veskoni,

I did not test #1, but #2 worked perfectly for what I needed. Thanks!

Paul
0
Frederik
Top achievements
Rank 1
answered on 01 Mar 2012, 10:03 AM
I know this thread is very old, but what I do using RadTreeView is you want to expand to a certain depth 'MaxDepth' which is defined elsewhere:

Protected Sub RadTreeView1_NodeDataBound(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeDataBound
e.Node.Expanded = e.Node.Level <= MaxDepth
End Sub

It's very similar code, just a bit shorter.
First post, be gentle.
Tags
TreeView
Asked by
Paul
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Paul
Top achievements
Rank 1
Frederik
Top achievements
Rank 1
Share this question
or