I’m trying to add nodes from a dataTable into a treeview. My problem isn’t the adding of the nodes however, it is displaying them. My loop goes through and adds every node. I have a text box that displays the total nodes correctly. However the treeview displays nothing. Am I missing some display property?
Thank you for your help!
oldComments.DataBind()
Dim count As Integer = 0
Dim TreeView1 As TreeView = New TreeView
' TreeView1.FindNode("My Node").ChildNodes().Add(New TreeNode("Test This"))
For Each row As DataRow In dsData.Rows
Dim node As TreeNode = New TreeNode(row("UpdateTimeStamp").ToString)
Dim node2 As TreeNode = New TreeNode((count.ToString + " - Count"), "test")
TreeView1.Nodes.Add(node2)
TreeView1.Nodes.Add(node)
TreeView1.Nodes(0).ChildNodes().Add(node)
Next
TreeView1.ExpandAll()
status.Text = TreeView1.Nodes.Count
Then the ASP:
<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
<asp:TreeNode Text="My Node" Value="My Node"></asp:TreeNode>
</Nodes>
</asp:TreeView>
I have added one node to see where it was displaying / try to use the find control to add a new child node and that didn’t work. Suggestions?
Thank you.
You are assigning the same node twice. Once to the treeview nodes and once to the child nodes of another node. You do not need to assign a node to the treeview itself if you are adding a child to some node. Change the code to