2010-10-24 30 views
2

我有以下定義地圖:使用ASP.net菜單控制有一個網站地圖

<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> 

我需要這在我的菜單控制,以顯示:首頁|項目|配置|您的賬戶|登出。

但是,當我導航到ProjectOverview和ProjectViewCalls頁面時,這是正常工作,我失去了列表項的所選class="level1 selected"屬性。我希望能夠指出用戶目前所在的網站區域。

這可能嗎?

回答

0

不知道這是你在找什麼,但這是一個簡單的方法來做到這一點。一個MenuItemDataBound事件添加到菜單控制,那麼在事件中使用此代碼:

 if(e.Item.Selected) 
     { 
      if(e.Item.Parent != null && e.Item.Parent.Selectable) 
      { 
       e.Item.Parent.Selected = true; 
      } 
     } 

如果你做到這一點,當前菜單項將不會有選定的樣式,所以它可能搞砸你的彈出子菜單。

如果不被顯示在所有子節點,你可以嘗試在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; 
    } 
} 

另一種選擇是拋棄默認菜單腳本,並使用類似Superfish代替。

+0

我沒有使用子菜單,我的網站地圖中的子節點的原因是因爲我希望所有項目相關頁面都選擇了項目菜單項。當瀏覽到其中一個「子頁面」時,e.Item.Selected從來就不是真的。 – 2010-11-03 15:19:55

+0

噢,好的。在這種情況下,可能是這樣的MenuDataBound: 'var currentNode = SiteMap.Provider.FindSiteMapNode(HttpContext.Current); if(currentNode!= null) \t { \t \t var parentMenuItem = Menu1.FindItem(「Root /」+ currentNode.ParentNode.Title); \t \t如果(parentMenuItem = NULL && parentMenuItem.Selectable!) \t \t { \t \t \t parentMenuItem.Selected = TRUE; \t \t} \t}' – Sprockincat 2010-11-03 21:37:39

+0

該死!對不起,搞砸了格式。我會在這裏再次嘗試:編輯:擰它,我只是在答案中發佈它。 – Sprockincat 2010-11-03 21:44:16

0
+0

請嘗試閱讀本文http://stackoverflow.com/help/deleted-answers,瞭解如何**不**回答。即:「不能從根本上回答問題的答案」:**僅僅是一個鏈接到外部網站** – 2013-10-29 06:17:21