Custom Navigation
Hi,
I am testing out the Custom Navigation option when using the Navigation control in Sitefinity 4 RC. In my master page I have the following for my main site navigation:
<
div
id
=
"nav"
>
<
asp:ContentPlaceHolder
id
=
"Nav"
runat
=
"server"
></
asp:ContentPlaceHolder
>
</
div
>
Hello carlag,
You can take a look at this post that shows how to apply a custom style to a given node
Greetings,
Ivan Dimitrov
the Telerik team
Hi, <%
I have created a user control with the following:
UserControl MarkUp:
@ Control Language="C#" AutoEventWireup="true" CodeFile="Navigation.ascx.cs" Inherits="Custom_Navigation" %>
<
telerik:RadSiteMap ID="RadSiteMap1" runat="server"></telerik:RadSiteMap>
public
partial class Custom_Navigation : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)
this.RadSiteMap1.NodeDataBound += new Telerik.Web.UI.RadSiteMapNodeEventHandler(RadSiteMap1_NodeDataBound);
protected void RadSiteMap1_NodeDataBound(object sender, Telerik.Web.UI.RadSiteMapNodeEventArgs e)
SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
SiteMapNode sitemapNode = e.Node.DataItem as SiteMapNode;
//e.Node.ToolTip = Page.ResolveUrl(currentNode.Url) + " - " + Page.ResolveUrl(sitemapNode.Url);
if (currentNode != null)
if (Page.ResolveUrl(sitemapNode.Url) == Page.ResolveUrl(currentNode.Url))
e.Node.Selected =
true;
e.Node.SelectedCssClass =
"testcurrent";
Hello carlag,
Below is a sample code
<asp:SiteMapDataSource runat=
"server"
ID=
"SiteMapDataSource1"
ShowStartingNode=
"false"
/>
<telerik:RadSiteMap runat=
"server"
ID=
"RadSiteMap1"
DataSourceID=
"SiteMapDataSource1"
></telerik:RadSiteMap>
RadSiteMap1.DataBind();
var selected =
this
.RadSiteMap1.SelectedNode;
if
(selected.Text ==
"sometext"
)
selected.CssClass =
"red"
;
HI,
I have tried the provided code sample, however, I am still not able to highlight the link for the current page.
I have the following in the user control markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Navigation.ascx.cs" Inherits="Custom_Navigation" %>
<
asp:SiteMapDataSource
runat
=
"server"
ID
=
"SiteMapDataSource1"
ShowStartingNode
=
"false"
/>
<
telerik:RadSiteMap
runat
=
"server"
ID
=
"RadSiteMap1"
></
telerik:RadSiteMap
>
public
partial
class
Custom_Navigation : System.Web.UI.UserControl
protected
void
Page_Load(
object
sender, EventArgs e)
RadSiteMap1.DataBind();
SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
var selected =
this
.RadSiteMap1.SelectedNode;
if
(Page.ResolveUrl(selected.NavigateUrl) == Page.ResolveUrl(currentNode.Url))
selected.CssClass =
"testcurrent"
;
Hello carlag,
Could you check whether the are any nodes added to the RadSiteMap by using GetAllNodes() method or Nodes property.
All the best,
Ivan Dimitrov
the Telerik team
Hi,
I have checked if there are any nodes added to RadSiteMap with this code in the user control (template):
public
partial
class
Custom_Navigation : System.Web.UI.UserControl
protected
void
Page_Load(
object
sender, EventArgs e)
RadSiteMap1.DataBind();
SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
var selected =
this
.RadSiteMap1.SelectedNode;
int
count = RadSiteMap1.GetAllNodes().Count;
Response.Write(count.ToString() +
"</br>"
);
foreach
(RadSiteMapNode node
in
RadSiteMap1.GetAllNodes())
node.ToolTip =
"This is tool tip text"
;
node.CssClass =
"testcurrent"
;
Response.Write(node.Value.ToString() +
"</br>"
+ Page.ResolveUrl(node.NavigateUrl).ToString() +
"</br>"
+ node.Selected.ToString() +
"</br>"
);
Here is what i have figured out in order to get the similar funcationality i had with the 3.7 sitemenu control to work in 4.0. For my main menu i only want to show the top level pages (Which is why maxdatabinddepth =1) and i also don't want to show a link to the home page which is why in the code behind i remove the first node in the prerender. Also since my menu doesn't show any submenus whenver a user is on a sub page i still want to highlight the parent menu node which is done by the while loop in the itemdatabound.
I made a new user control
the ascx looks like this
<
telerik:RadMenu
ID
=
"RadMenu1"
runat
=
"server"
DataSourceID
=
"SiteMap"
OnItemDataBound
=
"RadMenu1_ItemDataBound"
Width
=
"100%"
EnableEmbeddedSkins
=
"false"
Skin
=
"MySkin"
MaxDataBindDepth
=
"1"
>
</
telerik:RadMenu
>
<
asp:SiteMapDataSource
runat
=
"server"
ID
=
"SiteMap"
StartFromCurrentNode
=
"false"
ShowStartingNode
=
"false"
StartingNodeOffset
=
"0"
/>
using
Telerik.Sitefinity.Web;
using
Telerik.Web.UI;
namespace
SitefinityWebApp.Controls
public
partial
class
SiteMenu : System.Web.UI.UserControl
protected
void
Page_Load(
object
sender, EventArgs e)
protected
override
void
OnPreRender(EventArgs e)
base
.OnPreRender(e);
RadMenu1.DataBind();
RadMenu1.Items[0].Remove();
public
void
RadMenu1_ItemDataBound(
object
sender, RadMenuEventArgs e)
SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
while
(currentNode !=
null
&& currentNode.ParentNode !=
null
)
if
(currentNode.ParentNode.Title != currentNode.RootNode.Title)
currentNode = currentNode.ParentNode;
else
break
;
if
(currentNode !=
null
)
RadMenuItem item =
this
.RadMenu1.FindItemByUrl(
this
.ResolveUrl(currentNode.Url));
if
(item !=
null
)
item.Selected =
true
;
item.SelectedCssClass =
"rmFocused"
;