Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, here's what I ended up with. (Thanks, Leniel, for pointing me in the right direction.) The following code is in the code behind of the master file that contains the menu control. Comments in the code reveal my surprise that this control doesn't allow multiple items to be selected at one time. So, in a multi-level menu, I couldn't show as selected both the current node and it's parent. (Unless I'm missing something.)</p> <pre><code>// This is where we set the current node's ROOT menu item's selected property to // true. The current node won't show as selected, but it's parent will be. // As explained elsewhere, this was a UI decision based on the fact that the menu // can only have one menu item selected at a time. // If the menu wasn't dataBound, this code would be in Page_Load. protected void SideMenu_DataBound1(object sender, EventArgs e) { Menu menu = (Menu)this.FindControl("SideMenu"); // Get Menu Object string parent = null; // First check that there's a current node - there wont be one if the user // accesses this page from a bookmark. if (SiteMap.CurrentNode != null) { // Check if the current place in the SiteMap is in the first level of the menu // or a child menu item. if (SiteMap.CurrentNode.ParentNode.ParentNode != null) parent = SiteMap.CurrentNode.ParentNode.Description; // It's a child - has a parent if (parent == null) // a parent node { MenuItem item = menu.FindItem(SiteMap.CurrentNode.Description); item.Selected = true; } else // a child menu item { // Get it's parent node and set it's selected property to true. MenuItem item = menu.FindItem(parent); item.Selected = true; // Following comments left in to show how to get at // a menu item that's not in the first level. The trick is the // "/" separator, which is the pathSeparator property of the menu // control. // The menu control // only allows one item to be selected at a time. This is true, even though // the MenuItem class has a selected property, which implies each item // can have a selected property but it's not the case. //path = parent + "/" + current; //MenuItem item2 = menu.FindItem(path); //item2.Selected = true; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload