简体   繁体   中英

Asp.net Treeview strange behavior

I'm working with the treeview and I've seen that I can get the selected node, but when I try to look for it on TreeView I can't find it because TreeView.Nodes only has rootNode. What's happening?

I'm doing this on the same method:

  • First I get SelectedNode and
  • then I try to get its index using TreeView.Nodes.IndexOf(selectedNode), but Nodes only has rootNode.

This is the defenition of treeview on aspx page:

<asp:TreeView ID="DestinationTree" runat="server"  CssClass="destinationsTree" ExpandDepth="1" 
 onselectednodechanged="DestinationTree_SelectedNodeChanged" 
 ontreenodeexpanded="DestinationTree_TreeNodeExpanded" ShowLines="True" 
 Font-Names="&quot;Segoe UI&quot;,Frutiger,Tahoma,Helvetica,&quot;Helvetica Neue&quot;,Arial,sans-serif">
 <ParentNodeStyle Font-Bold="False" />
 <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
 <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />
 <Nodes>

TreeView is inside an Ajax UpdatePanel. I use TreeNodeExpand to add more nodes, and SelectedNodeChange to enable and disable buttons.

Any adviced?

Every node also has a Nodes property. Use a recursive function to walk the tree to find it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM