SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

spregards

share|improve this question

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

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

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)
                {
                        LeftNavTreeView.CollapseAll();

                        var treeNodeToExpand = LeftNavTreeView.SelectedNode;

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

Your Answer

 
discard

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.