Click here to Skip to main content
13,145,603 members (30,124 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 25 Feb 2008

To Edit ASP.Net Treeview's selected node using Java Script

, 25 Feb 2008
Rate this:
Please Sign up or sign in to vote.
Presents how to change the node text of ASP.Net using Java Script


This article will help to modify the text of the selected node of ASP.NET Tree View. I hope I can explain this in a simple manner so that people can easy to understand and implement it. I did this for my application and I could avoid the page post back.

Using the code

I have bound the Tree View like below:

TreeNode root = new TreeNode("School");

TreeNode teach = new TreeNode("Teachers");
TreeNode stud = new TreeNode("Students");

TreeNode teach1 = new TreeNode("Teacher1");
TreeNode teach2 = new TreeNode("Teacher2");
TreeNode teach3 = new TreeNode("Teacher3");

TreeNode stud1 = new TreeNode("Student1");
TreeNode stud2 = new TreeNode("Student2");
TreeNode stud3 = new TreeNode("Student3");
TreeNode stud4 = new TreeNode("Student4");

teach.ChildNodes.Add(teach1); teach.ChildNodes.Add(teach2);

stud.ChildNodes.Add(stud1); stud.ChildNodes.Add(stud2);
stud.ChildNodes.Add(stud3); stud.ChildNodes.Add(stud4);

root.ChildNodes.Add(teach); root.ChildNodes.Add(stud);


And attach this java script event to the Treeview

this.TreeView1.Attributes.Add("oncontextmenu", "RightClick(event);");

Java script code:

function RightClick(event)
    var obj = event.srcElement || ;
    var seltreeNode = obj; 
    alert(seltreeNode.innerHTML); //This will prompt selected Node Text
    seltreeNode.innerHTML = "Rajesh Babu"; //This will change the selected node text as "Rajesh Babu"

Happy Coding!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

RB Changanacherry
Team Leader
India India
I am Rajesh Babu, currently working for Nous Infosystems, Bangalore. I have 6 plus years experience in Microsoft Technologies.

You may also be interested in...


Comments and Discussions

QuestionJavaScript for Treeview Pin
Member 120452329-Oct-15 22:31
memberMember 120452329-Oct-15 22:31 
GeneralMy vote of 5 Pin
manoj kumar choubey16-Feb-12 0:09
membermanoj kumar choubey16-Feb-12 0:09 
GeneralThis got me unstuck. Pin
James Avary7-Jun-11 5:09
memberJames Avary7-Jun-11 5:09 
QuestionIs it posible to Add a new node in javascript? Pin
maluche11-Apr-08 8:25
membermaluche11-Apr-08 8:25 
AnswerRe: Is it posible to Add a new node in javascript? Pin
vinicius akira marotta8-Jul-08 7:59
membervinicius akira marotta8-Jul-08 7:59 
GeneralRe: Is it posible to Add a new node in javascript? Pin
norhani19-Nov-08 15:42
membernorhani19-Nov-08 15:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 26 Feb 2008
Article Copyright 2008 by RB Changanacherry
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid