How to dynamically add nodes to the TreeView control at runtime In Asp.Net


This article used to develop application using Tree View In Asp.Net

Following code help to dynamically add nodes to the TreeView control at runtime in .net application.



Private Sub BuildTreeView()
' For this part of the sample, the tree view will look like the following hierarchy:

'TechBook()
'| |
'| |__ ASP.net
'| |
'| |__ JAVA
'|
'Novel()


Dim BookTitles As String() = {"Gladiator", "Harry Potter and the Sorcerer's Stone", "Star Wars: The Empire Strikes Back", "The Lord of the Rings: The Two Towers"}

Dim JAVATitles As String() = {"Chevelle: Wonder What's Next", "Foo Fighters: The Colour and the Shape", "Stone Temple Pilots: Core"}

Dim NovelTitles As String() = {"2001: A Space Odyssey", "The Godfather", "Casablanca", "Ctizien Kane"}


Dim TechBookNode As New TreeNode("TechBook")
TreeView1.Nodes.Add(TechBook)


Dim ASPnetNode As New TreeNode("ASP.net")
TechBookNode .ChildNodes.Add(ASPnetNode)


Dim i As Integer
For i = 0 To BookTitles.Length - 1
Dim node As New TreeNode(BookTitles(i))
ASPnetNode.ChildNodes.Add(node)
Next i


Dim JAVANode As New TreeNode("JAVA")
TechBookNode.ChildNodes.Add(JAVANode)


For i = 0 To JAVATitles.Length - 1
Dim node As New TreeNode(JAVATitles(i))
JAVANode.ChildNodes.Add(node)
Next i


Dim TechBookNode As New TreeNode("TechBook")
TreeView1.Nodes.Add(TechBookNode)


For i = 0 To Novel.Length - 1
Dim node As New TreeNode(NovelTitles(i))
NovelNode.ChildNodes.Add(node)
Next i
End Sub
End Class


Comments

Author: Atul Sharma07 Jan 2015 Member Level: Silver   Points : 2

http://www.codeproject.com/KB/webforms/ClientSideTreeView.aspx
http://msdn.microsoft.com/en-us/library/e8z5184w%28VS.80%29.aspx
http://aspalliance.com/732

http://www.dotnetspider.com/resources/38757-How-To-Use-Tree-View-In-Asp-Net.aspx



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: