开发者

TreeView - OnSelectedNodeChanged not firing for Programmatically Added Nodes

I've been searching, including similar questions here to no avail. If I click on a node that I've added to a TreeView, the OnSelec开发者_运维百科tedNodeChanged event does not fire. Even ignoring that, just on a Page_Load(), the SelectedNode property is null.

My TreeView control is:

<asp:TreeView runat="server" ID="TheView" OnTreeNodePopulate="Populate" OnSelectedNodeChanged="SelectNode" />

In my code behind, I add one node:

TreeNode node = new TreeNode( "Root", "1" );
node.PopulateOnDemand = true;
node.SelectAction = TreeNodeSelectAction.Select;
TheView.Nodes.Add( node );

Subordinate nodes are added identically:

foreach ( MyMenuItem item in list )
{
    TreeNode newNode = new TreeNode( item.DisplayName, item.Value );

    newNode.PopulateOnDemand = true;
    newNode.SelectAction = TreeNodeSelectAction.Select;
    node.ChildNodes.Add( newNode );
}

Everything shows up in the tree as I would expect, the page reloads when I click a node, but then nothing! What am I missing?


I have no idea what this is all about, legacy code and all, but this post at forums.asp.net showed me the way. There's a CSSFriendlyAdapter in my CSSMenuAdapter.browser file. Deleting that made it work... and makes the tree view look better, too.


I have a programmatic treeview that I load similarly to the way you load yours. The SelectedNodeChanged Event fires on mine, but because the selecting a node reloads the page, and therefore the tree, I have to tell the tree which node is selected every time it loads. I do this by using

If Request.PhysicalPath = Server.MapPath(myNode.NavigateUrl) Then
     myNode.Selected = True
End If 

when the nodes are loaded. It's a hack, and it's in VB, but maybe it'll point you in the right direction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜