How to get list of all parent node values

6 posts, 0 answers
  1. Manoj
    Manoj avatar
    75 posts
    Member since:
    Dec 2008

    Posted 06 Feb 2009 Link to this post

    Hi Team,
        How can we get the list of parent node value at a perticular level .?
    My requirment is I have to pass the list of parent node value as a string ( each node will separated with a comma ) at a perticular level . If I am expanding the level 4 then , I need parentnodevalue(0),parentnodevalue(1),parentnodevalue(2),parentnodevalue(3),currentnodevalue(4) . can you suggest me

    Regards
    Manoj
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Feb 2009 Link to this post

    Hi Manoj,

    I have used the following code to get the parent of a selected node.

     <radT:RadTreeView ID="RadTreeView1" runat="server" OnNodeClick="RadTreeView1_NodeClick" AutoPostBack=true>  
            </radT:RadTreeView> 

    protected void RadTreeView1_NodeClick(object o, RadTreeNodeEventArgs e)  
        {  
            SelectParents(e.NodeClicked);  
        }  
     
        protected void SelectParents( RadTreeNode node)  
        {  
            if (node.Parent != null)  
            {  
                node.Parent.Selected = true;  
               
            }  
        } 

    You can loop through the node collection and get the parent nodes 

    foreach (RadTreeNode node in nodeCollection)
                {
    //Write the logic to find the parent up to the selected node.               
                }


    -Shinu.
  3. Manoj
    Manoj avatar
    75 posts
    Member since:
    Dec 2008

    Posted 09 Feb 2009 Link to this post

    Hi Shinu,
        Thanks for your reply . But I getting compile time error when trying to check your suggested code . Can you look into it .
    When I am expanding any perticular node , I need all the parent node values .

    Regards
    Manoj
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Feb 2009 Link to this post

    Hi  Manoj,

    Give a try with the following client side code and see whether it helps.

    ASPX:
     
     
    <telerik:RadTreeView ID="RadTreeView1"   runat="server" OnClientNodeExpanding="ClientNodeExpanding" > 
                           <Nodes> 
                             ...... 

    JS:
    <script type="text/javascript" > 
     function ClientNodeExpanding(sender, eventArgs) 
     { 
       var Tree=sender; 
       var nodes=Tree.get_nodes(); 
     
       var currentNode = eventArgs.get_node();   
       if(currentNode!=null)   
       { 
         for(i=0;i<=nodes.get_count();i++) 
          { 
          
            var nodeText=nodes.getNode(i).get_text(); 
             alert(nodeText) 
            if(nodeText==currentNode.get_text()) 
            { 
              break
            } 
           } 
       } 
     } 
    </script> 


    Thanks
    Shinu



  5. Manoj
    Manoj avatar
    75 posts
    Member since:
    Dec 2008

    Posted 13 Feb 2009 Link to this post

    Hi Shinu,

                 Thanks for you reply . I tried in a different manner . Here I have attached the code .

     

    RadTreeNode

    curNode;

     

     

    String strNodeCollection = "";

     

     

    String strNodeColl = "";

     

    curNode = e.Node;

     

    Int32 intSelectedNodeLevel;

     

    intSelectedNodeLevel = e.Node.Level;

     

    if (intSelectedNodeLevel >= 0)

     

    {
        

    for (int i = intSelectedNodeLevel; i >= 0; i--)

     

        {

     

            if (strNodeCollection == "")

     

            {

                strNodeColl = curNode.Value;

                strNodeCollection = strNodeColl;

            }

     

            else 

     

            {

     

                RadTreeNode tnode = curNode.ParentNode;

     

                strNodeCollection = tnode.Value +

    "," + strNodeCollection ;

     

                curNode = tnode;

            }

        }

    }

    With Regards
    Manoj

  6. Richard
    Richard avatar
    63 posts
    Member since:
    Apr 2008

    Posted 18 Jun 2009 Link to this post

    Manoj,

    Thanks, that method was EXACTLY what I was looking for!!!
Back to Top