Click here to Skip to main content
6,629,377 members and growing! (20,489 online)
Email Password   helpLost your password?
Web Development » ASP.NET Controls » General     Intermediate License: The Code Project Open License (CPOL)

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

By RB Changanacherry

Presents how to change the node text of ASP.Net using Java Script
Javascript, CSS, HTML, C# 2.0, Java, .NET 2.0, ASP, ASP.NET, Ajax, Architect, Dev
Posted:25 Feb 2008
Views:30,982
Bookmarked:12 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 1.81 Rating: 2.00 out of 5
4 votes, 50.0%
1
1 vote, 12.5%
2
1 vote, 12.5%
3

4
2 votes, 25.0%
5

Introduction

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);
teach.ChildNodes.Add(teach3);

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

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

TreeView1.Nodes.Add(root);

		

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 || event.target ;
    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!

License

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

About the Author

RB Changanacherry


Member
I am Rajesh Babu, currently working for Nous Infosystems, Bangalore. I have 6 plus years experience in Microsoft Technologies.
Occupation: Team Leader
Location: India India

Other popular ASP.NET Controls articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralIs it posible to Add a new node in javascript? Pinmembermaluche9:25 11 Apr '08  
GeneralRe: Is it posible to Add a new node in javascript? Pinmembervinicius akira marotta8:59 8 Jul '08  
GeneralRe: Is it posible to Add a new node in javascript? Pinmembernorhani16:42 19 Nov '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Feb 2008
Editor:
Copyright 2008 by RB Changanacherry
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project