This is a migrated thread and some comments may be shown as answers.

RadTreeView Load-On-Demand expanding node not working

1 Answer 179 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
shaun pitt
Top achievements
Rank 1
shaun pitt asked on 23 Jun 2010, 03:50 AM
Hi There,

We are using RadTreeView as a replacement for the menu in SharePoint. It is connecting to a datasource we have generated from the SPSites, basically creating a new SiteMapProvider. This is all in code behind. We have set the ExpandMode to "ServerSideCallBack" for efficiency reasons. But when I navigate to child sites, it doesn't show the currently selected node when the page is loaded......how can we achieve this???

please help

Snippets:

SharePoint MasterPage:

<%@ Master language="C#" Inherits="Chisholm.SharePoint.MasterPages.StudentPortal, Chisholm.SharePoint.MasterPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=36b5e3431f62f80f" %>

...........................................

<telerik:RadTreeView ID="myLearningTreeView" runat="server" Skin="Office2007"
            DataSourceID="MyLearningDS"
            OnNodeExpand="NodeExpandHandler"
            MaxDataBindDepth="1"
            DataNavigateUrlField="Url"
            DataTextField="Title" DataValueField="Key" DataFieldID="Key"  EnableEmbeddedSkins="False" SingleExpandPath="True">
            <DataBindings>
    <telerik:RadTreeNodeBinding ExpandMode="ServerSideCallBack" Depth="0" />
   </DataBindings>
        </telerik:RadTreeView>
        <asp:SiteMapDataSource ID="MyLearningDS" runat="server"
                ShowStartingNode="false"
                StartFromCurrentNode="false"
                StartingNodeOffset="0"
                SiteMapProvider="MyPortalSiteMapProvider"
                StartingNodeUrl="/myLearning"/> 

............................


code behind: StudentPortal.cs

namespace

 

Chisholm.SharePoint.MasterPages

 

{

 

 

public class StudentPortal : MasterPage

 

{

 

 

protected global::Telerik.Web.UI.RadTreeView myLearningTreeView;

 

 

 

public RadTreeNode LastSelectedNode

 

{

 

 

get { return (RadTreeNode)ViewState["LastSelectedNode"]; }

 

 

 

set { ViewState["LastSelectedNode"] = value; }

 

}

 

 

 

public RadTreeView SiteMenu

 

{

 

 

get { return (RadTreeView)ViewState["SiteMenu"]; }

 

 

 

set { ViewState["SiteMenu"] = value; }

 

}

 

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

 

//if (!Page.IsPostBack)

 

 

 

//{

 

 

 

if ((SiteMenu!=null)&&(LastSelectedNode!=null))

 

{

 

 

// get the custom sql site map provider

 

 

SqlSiteMapProvider provider = ((SqlSiteMapProvider)SiteMap.Providers[

"MyPortalSiteMapProvider"]);

 

 

 

if (provider == null)

 

 

 

return;

 

 

 

// add a method to get chid nodes by Key

 

 

SiteMapNode siteNode = provider.FindSiteMapNodeFromKey(LastSelectedNode.Value);

 

if (siteNode == null)

 

 

 

return;

 

SiteMapNodeCollection childNodes = provider.GetChildNodes(siteNode);

 

 

if (childNodes.Count < 1)

 

 

 

return;

 

 

 

// NW: call FindSiteMapNodeFromKey() of the SiteMapProvider using

 

 

 

// the key obtained from the node that was clicked.

 

 

 

// The node that was clicked becomes the new parent of the children

 

 

 

// to be added to it from the database.

 

 

 

//

 

 

 

foreach (SiteMapNode child in childNodes)

 

{

 

 

// NW: The children are created based on the information obtained from

 

 

 

// the database.

 

 

 

//

 

 

 

// create a new node

 

 

RadTreeNode rtn =

new RadTreeNode()

 

{

Value = child.Key,

Text = child.Title,

ExpandMode = TreeNodeExpandMode.ServerSide,

 

//NW: This is overiden below.

 

 

NavigateUrl = child.Url,

LongDesc = child.Description

};

 

// with the same expand mode as the node currently expanding

 

 

rtn.ExpandMode = LastSelectedNode.ExpandMode;

 

// add the new node to the node that is expanding

 

 

LastSelectedNode.Nodes.Add(rtn);

}

 

// now that the nodes are added, change the current node's expand mode to client-side

 

 

LastSelectedNode.ExpandMode = TreeNodeExpandMode.ClientSide;

 

// signal that the node is now expanded

 

 

LastSelectedNode.Expanded =

true;

 

}

 

 

//}

 

 

}

 

protected void NodeExpandHandler(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)

 

{

SiteMenu = (RadTreeView)sender;

LastSelectedNode = e.Node;

 

 

// get the custom sql site map provider

 

 

SqlSiteMapProvider provider = ((SqlSiteMapProvider)SiteMap.Providers[

"MyPortalSiteMapProvider"]);

 

 

 

if (provider == null)

 

 

 

return;

 

 

 

// add a method to get chid nodes by Key

 

 

SiteMapNode siteNode = provider.FindSiteMapNodeFromKey(e.Node.Value);

 

if (siteNode == null)

 

 

 

return;

 

SiteMapNodeCollection childNodes = provider.GetChildNodes(siteNode);

 

 

if (childNodes.Count < 1)

 

 

 

return;

 

 

 

// NW: call FindSiteMapNodeFromKey() of the SiteMapProvider using

 

 

 

// the key obtained from the node that was clicked.

 

 

 

// The node that was clicked becomes the new parent of the children

 

 

 

// to be added to it from the database.

 

 

 

//

 

 

 

foreach (SiteMapNode child in childNodes)

 

{

 

 

// NW: The children are created based on the information obtained from

 

 

 

// the database.

 

 

 

//

 

 

 

// create a new node

 

 

RadTreeNode rtn =

new RadTreeNode()

 

{

Value = child.Key, Text = child.Title,

ExpandMode = TreeNodeExpandMode.ServerSide,

 

//NW: This is overiden below.

 

 

NavigateUrl = child.Url, LongDesc = child.Description

};

 

// with the same expand mode as the node currently expanding

 

 

rtn.ExpandMode = e.Node.ExpandMode;

 

// add the new node to the node that is expanding

 

 

e.Node.Nodes.Add(rtn);

}

 

// now that the nodes are added, change the current node's expand mode to client-side

 

 

e.Node.ExpandMode = TreeNodeExpandMode.ClientSide;

 

// signal that the node is now expanded

 

 

e.Node.Expanded =

true;

 

}

NOTE:

 

 // we are not using the following code

 

 

protected void NodeClickHandler(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)

 

{

SiteMenu = (RadTreeView)sender;

LastSelectedNode = e.Node;

}

}

}

once again please help......we have a critical situation here that we are so close to fixing, and this is holding us back.

ps...tried attaching a zip!

regards
Shaun Pitt
Chisholm Institute - Australia

 

1 Answer, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 28 Jun 2010, 11:46 AM
Hi shaun pitt,

You can select the node which contains the url of the current content page by the following line:
Copy Code
(Page.Master.FindControl("<the ID of the tree>") as RadTreeView).FindNodeByUrl(Request.Url.PathAndQuery).Selected = true;

Basically, from the content page you are accessing the treeView in the masterPage and knowing the current url, you are searching for a node with the same url and finally setting its Selected property to true!

You should add this to all content pages (at least these that can be navigated from the treeView) and the node which is source of the navigation will always be selected.

Also be careful for pages that are not represented in the treeView - they shouldn't have this applied.

Hope this is going to help you!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
shaun pitt
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Share this question
or