[英]Using ASP.net Menu Control with a sitemap
I have following sitemap defined: 我定义了以下站点地图:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="Root" roles="*">
<siteMapNode url="~/Default.aspx" title="Home" roles="*" />
<siteMapNode url="~/ProjectList.aspx" title="Projects" roles="*">
<siteMapNode url="~/ProjectOverview.aspx" title="Project Overview" roles="*" />
<siteMapNode url="~/ProjectViewCalls.aspx" title="View Calls" roles="*" />
</siteMapNode>
<siteMapNode url="~/Configuration.aspx" title="Configuration" roles="Administrator" />
<siteMapNode url="~/YourAccount.aspx" title="Your Account" roles="Administrator" />
<siteMapNode url="~/Logout.aspx" title="Logout" roles="*" />
</siteMapNode>
</siteMap>
I need this to display in my menu control as: Home | 我需要将其显示在菜单控件中,如下所示: Projects |
项目| Configuration |
配置| Your Account |
您的帐号| Logout.
登出。
This is working correctly however when i navigate to the pages ProjectOverview and ProjectViewCalls, I lose the selected class="level1 selected"
attribute of the list item. 这是正常工作,但是当我导航到ProjectOverview和ProjectViewCalls页面时,我丢失了列表项的selected
class="level1 selected"
属性。 I want to be able to indicate what area of the site the user is currently in. 我希望能够指出用户当前所在的网站区域。
Is this possible? 这可能吗?
I have written a detailed article for this at codeproject ( http://www.codeproject.com/Articles/669717/How-to-correctly-use-sitemap-for-top-left-menus ) and here ( http://mangeshdevikar.enziq.com/how-to-correctly-use-sitemap-for-topleft-menus/ ) . 我在codeproject( http://www.codeproject.com/Articles/669717/How-to-correctly-use-sitemap-for-top-left-menus )和此处( http:// mangeshdevikar.enziq.com/如何正确使用sitemap-for-topleft-menus / )。 Hope it helps.
希望能帮助到你。
Not sure if this is what you're looking for, but here is an easy way to do it. 不确定这是否是您想要的,但是这是一种简单的方法。 Add a MenuItemDataBound event to the menu control, then in the event use this code:
将MenuItemDataBound事件添加到菜单控件,然后在该事件中使用以下代码:
if(e.Item.Selected)
{
if(e.Item.Parent != null && e.Item.Parent.Selectable)
{
e.Item.Parent.Selected = true;
}
}
If you do this, the current menu item will not have the selected style, so it might mess up your pop-out sub menu. 如果这样做,当前菜单项将不会具有所选样式,因此可能会弄乱弹出子菜单。
If the child nodes aren't being displayed at all, you could try binding something like this on MenuDataBound: 如果根本不显示子节点,则可以尝试在MenuDataBound上绑定如下所示的内容:
var myMenu = (Menu) sender;
var currentNode = SiteMap.Provider.FindSiteMapNode(HttpContext.Current);
if (currentNode != null)
{
var parentMenuItem = myMenu.FindItem("Root/" + currentNode.ParentNode.Title);
if (parentMenuItem != null && parentMenuItem.Selectable)
{
parentMenuItem.Selected = true;
}
}
Another option would be to ditch the default menu script and use something like Superfish instead. 另一个选择是放弃默认菜单脚本,而改用Superfish之类的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.