Hi Guru's. Please help me here.
If I load a Treeview with static data such as
<Nodes>
<asp:TreeNode Text="Chapter 1" SelectAction="Expand">
<asp:TreeNode Text="Section 1" />
<asp:TreeNode Text="Section 2" />
</asp:TreeNode>
<asp:TreeNode Text="Chapter 2" SelectAction="Expand">
<asp:TreeNode Text="Section 1" />
<asp:TreeNode Text="Section 2" />
</asp:TreeNode>
</Nodes>
When the treeview.SelectedNodeChanged event triggers I get the correct treeview.SelectedNode.Text. But if I load the treeview programmatically with
Protected Sub LoadTreeView()
Dim D1Node, D2Node As TreeNode
TreeView1.Nodes.Clear()
Dim RootNode As TreeNode = New TreeNode("root node")
TreeView1.Nodes.Add(RootNode)
D1Node = New TreeNode(UCase("Chapter 1"), "Dir1")
RootNode.ChildNodes.Add(D1Node)
D2Node = New TreeNode("Section 1", "Dir2")
D1Node.ChildNodes.Add(D2Node)
D2Node = New TreeNode("Section 2", "Dir2")
D1Node.ChildNodes.Add(D2Node)
D1Node = New TreeNode(UCase("Chapter 2"), "Dir1")
AssociationNode.ChildNodes.Add(D1Node)
D2Node = New TreeNode("Section 1", "Dir2")
D1Node.ChildNodes.Add(D2Node)
D2Node = New TreeNode("Section 2", "Dir2")
D1Node.ChildNodes.Add(D2Node)
End Sub
This produces the same treeview (in the browser with the exception of the added "root node") as the xml version BUT the selectednode does not work the same. The selectednode is always the first one in the list at each level. For example if I select "Chapter 1" I get "Chapter 1" but if I select "Chapter 2" the selected node is "Chapter 1". Ditto with Section 1 and Section 2. If I select "Section 2" the selected node is "Section1". I only load the grid one time on a non-postback.
What am I missing here?
Thanks,
Eric