Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using an customized SPTreeView (UserControl) embed on the masterpage, any ideas how to set the selectedNode that correspond to the contextWeb or using another approach?


share|improve this question

2 Answers 2

That's little tricky.. Let's assume you have following binding for your SPTreeview

                <asp:TreeNodeBinding SelectAction="Select" NavigateUrlField="" TextField="EncodedName"
                    Target="_blank" ValueField="Name" />

Then, in PreRender, you need to set the SelectedNodePath as shown below

 protected override void OnPreRender(EventArgs e)

                WebTreeView.SelectedNodePath = "value that corresponds to current web";

share|improve this answer
thanks for the reply @ashish-patel, but still not working. protected override void OnPreRender(EventArgs e) { var web = SPControl.GetContextWeb(Context); WebTreeView.SelectedNodePath = web.Url; WebTreeView.AutoExpandSelectedNode = true; } –  fallout Feb 14 '12 at 9:20
up vote 0 down vote accepted

using TreeView instead of SPTreeView:

protected void LeftNavTreeView_OnPreRender(object sender, EventArgs e)

                        var treeNodeToExpand = LeftNavTreeView.SelectedNode;

                        while (treeNodeToExpand != null)
                                treeNodeToExpand = treeNodeToExpand.Parent;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.