ExpandDepth equivilent?

4 posts, 1 answers
  1. Paul
    Paul avatar
    76 posts
    Member since:
    Feb 2008

    Posted 20 Mar 2008 Link to this post

    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!
  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 24 Mar 2008 Link to this post

    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
  3. Paul
    Paul avatar
    76 posts
    Member since:
    Feb 2008

    Posted 24 Mar 2008 Link to this post

    Veskoni,

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

    Paul
  4. Frederik
    Frederik avatar
    2 posts
    Member since:
    Jul 2011

    Posted 01 Mar 2012 Link to this post

    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.
Back to Top