开发者

dynamic treeview population in a sharepoint webpart

I am trying to dynamically populate a treeview object on a sharepoint webpart. For some reason, the node population is triggered automatically and without user input. Below is a sample of how I set up the tree and webpart.

Any suggestions on how to prevent the automatic populate would be appreciated.

The following is in开发者_如何转开发 the createchildcontrols method:

                this.Tree = new TreeView();
                this.Tree.EnableClientScript = false;
                this.Tree.PopulateNodesFromClient = true;
                this.Tree.Nodes.Add(this.FetchTreeNode());
                this.Tree.TreeNodePopulate += new TreeNodeEventHandler(Tree_TreeNodePopulate);

The handler looks like this:

void Tree_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
       List<MyNode> children = this.FetchChildren(e.Node.Value);
       foreach (MyNode child in children)
       {
           TreeNode node = new TreeNode(child.Name, child.UniqueId, child.IconPath);
           node.PopulateOnDemand = true;
           node.SelectAction = TreeNodeSelectAction.Expand;
           e.Node.ChildNodes.Add(node);
       }
    }

I've been banging my head on this one for a long time, any suggestions would be appreciated.


So I finally figured this out... for some reason, the default behavior of the treeview was to be expanded, so it would call the treenode populate function right off the bat. I was able to get this to work by calling the treeview.collapseall() method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜