How to get parent node value

4 posts, 2 answers
  1. Patxi
    Patxi avatar
    70 posts
    Member since:
    Feb 2009

    Posted 21 Apr 2009 Link to this post

    Hi,

    I have got this structure:

    Node 1
           Node 1.1
           Node 1.2
           Node 1.3
    Node 2
           Node 2.1
           Node 2.2

    When clicking on any child node I need to get the value of the selected parent node.

    Do you have an example which may help me?

    Thank you.
  2. Answer
    Paul
    Admin
    Paul avatar
    4281 posts

    Posted 21 Apr 2009 Link to this post

    Hello Patxi,

    Here's a sample code snippet that shows the needed appraoch.

        <form id="form1" runat="server">  
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
        </telerik:RadScriptManager> 
     
        <script type="text/javascript">  
            function OnClientNodeClicked(sender, eventArgs) {  
                var node = eventArgs.get_node();  
                if (node.get_level() != 0) {  
                    var parentNode = node.get_parent();  
                    alert(parentNode.get_value());  
                }  
            }  
     
        </script> 
     
        <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientNodeClicked="OnClientNodeClicked">  
            <Nodes> 
                <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1" Value="root1">  
                    <Nodes> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
                        </telerik:RadTreeNode> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
                        </telerik:RadTreeNode> 
                    </Nodes> 
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Text="Root RadTreeNode2" Value="root2">  
                    <Nodes> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
                        </telerik:RadTreeNode> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
                        </telerik:RadTreeNode> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 3">  
                        </telerik:RadTreeNode> 
                    </Nodes> 
                </telerik:RadTreeNode> 
            </Nodes> 
        </telerik:RadTreeView> 
        </form> 


    Regards,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Apr 2009 Link to this post

    Hello Patxi,

    The server side equivalent for the above code is as follows:
    c#:
    protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e) 
        { 
            RadTreeNode myParentNode = e.Node.ParentNode; 
            if (myParentNode != null
            { 
                string mynode = myParentNode.Text; 
            } 
        } 

    Thanks
    Princy.
  4. Patxi
    Patxi avatar
    70 posts
    Member since:
    Feb 2009

    Posted 21 Apr 2009 Link to this post

    Thanks Paul and Princy!

    fast answer and better solution :)

    Both are all right.
Back to Top