Link to home
Start Free TrialLog in
Avatar of AVARICESOFT
AVARICESOFTFlag for Pakistan

asked on

i want to find the parent node in treeview using javascript

hello i am create asp.net web application using C#.net

i want to find the parent node of the new node if its exist then add to the another treeview here is the sample code given below

the classes node is statically define in the treeview..

kindly help me how could i find the node parent and then insert in the snode

thanks
function ClassNodeEdit(sender, eventArgs) {
               var node1 = eventArgs.get_node();
                var nodeText = node1.get_text();


                var tree = $find("tree_test");
                var snode = tree.findNodeByText("Classes");

                tree.trackChanges();




                var node = new Telerik.Web.UI.RadTreeNode();
                node.set_text(node1.get_text());
                snode.get_nodes().add(node);
                tree.commitChanges();
            }

Open in new window

Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

just use get_parent():
for example:

function GetParent()
{
   var tree= $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByAttribute("MyCustomAttribute", "Some Value");
   node.get_parent().expand();
   node.select();
}




u can use this link for treeview api:
http://www.telerik.com/help/aspnet-ajax/tree_clientradtreenode.html
so in your case it would be something like this:

var tree = $find("tree_test");
                var snode = tree.findNodeByText("Classes");


var node = new Telerik.Web.UI.RadTreeNode();
                node.set_text(snode.get_parent().get_text());
                snode.get_nodes().add(node);
                tree.commitChanges();
sorry i misused your code, i though the snode is the one ur looking for.
u probably familiar with your code more than i, so if get_parent() doesn't work for you let me know.
ASKER CERTIFIED SOLUTION
Avatar of Saber37886661
Saber37886661

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AVARICESOFT

ASKER

hey man ur are almost right but kindly give me code of that suppose:

i have 1 RadTreeView1 and 2nd RadTreeView2

i only want to add the node which is added on the RadTreeView1 by hierarchy ..

this function automatically call when RadTreeView1 node created dynamically

function ClassNodeEdit(sender, eventArgs) {
}

i only want to copy the nodes from RadTreeView1 to RadTreeView2 according to hieracry like parents is parent and child is child nothing more..  but in javascript clientside

the ClassNodeEdit function is called when the RadTreeView1 Node is create...

Thanks.

thanks i get the solution