Using menu control with sitemapdatasource

G

gjergj

Hi,

I am trying to use the menu control to create a menu similar to the one
that ASP.net site has and I am having a little trouble. The menu is
binded to a sitemapdatasource and are both placed on a master page. The
sitemapdatasource has ShowStartingMode set to false and the sitemap
file looks like:

StartNode
Home
Reports
Report 1
Report 2
Report 3
Projects
Project

The Menu control looks like:


<asp:Menu ID="Menu1" runat="server"

DataSourceID="SiteMapDataSource1" MaximumDynamicDisplayLevels="0"

Orientation="Horizontal" EnableViewState="true" StaticDisplayLevels=2>

<StaticMenuItemStyle BackColor=Aqua />

<StaticSelectedStyle BackColor=Beige />

</asp:Menu>


The problem I am having is that when the user clicks through a link on
the page that leads to Report 1, nothing is selected in the menu - but
i need the Reports to be selected as Report 1 is a child of Reports.

Any idea on how to solve this problem?

thanks

tony
 
Joined
Apr 25, 2008
Messages
1
Reaction score
0
Hi,

you can write the following code in menu1_DataBound event:


SiteMapNode currNode = SiteMapDataSource1.Provider.CurrentNode;

if (currNode != null && (currNode.ParentNode != currNode.RootNode))
{
SiteMapNode node = currNode.RootNode.ChildNodes[0];

foreach (MenuItem pMenu in menu1.Items)
{
if (currNode.IsDescendantOf(node))
{
pMenu.Selected = true;
break;
}
node = node.NextSibling;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top