|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
asp.net menu to show only parent, siblings and children as static menusAnyone have any idea how to have an asp.net menu show only the parent,
siblings and immediate children of the current node? It seems like the ultimate way to navigate a large sitemap. I've set the StartFromCurrentNode="true" and StartingNodeOffset="-1" on the SitemapDataSource and set the number of static menu levels to 3 on the menu. However, this ends up displaying the children of all the siblings as well (which makes the menu much too large). Ideas? Thanks, Clint Clint,
I'm sure this isn't the best solution, but it's what I had time to come up with. It could definitely use a better test in the IsSamePage method, but I couldn't come up with one at the moment.... Hopefully this will get you on the right track. protected void Page_Load(object sender, EventArgs e) { // Find the menu item (if any) that corresponds to this page... MenuItem theItem = FindMenuItem(Menu1.Items); // Now, figure out which parent item it belongs to. MenuItem theParent = GetItemParent(theItem); // Finally, remove all children from the other top-level menu items. RemoveChildrenOfOthers(Menu1.Items, theParent); } private bool IsSamePage(string TargetUrl) { return Server.MapPath(Request.Url.LocalPath) == Server.MapPath(TargetUrl); } private MenuItem FindMenuItem(MenuItemCollection mis) { foreach (MenuItem mi in mis) { if (IsSamePage(mi.NavigateUrl)) return mi; else { MenuItem mi2 = FindMenuItem(mi.ChildItems); if (mi2 != null) return mi2; } } return null; } private MenuItem GetItemParent(MenuItem mi) { if (mi.Parent == null) return mi; else return GetItemParent(mi.Parent); } private void RemoveChildrenOfOthers(MenuItemCollection all, MenuItem keep) { foreach (MenuItem mi in all) { if (mi != keep) mi.ChildItems.Clear(); } } Cheers, Kelly Show quoteHide quote "Clint" wrote: > Anyone have any idea how to have an asp.net menu show only the parent, > siblings and immediate children of the current node? > > It seems like the ultimate way to navigate a large sitemap. I've set > the StartFromCurrentNode="true" and StartingNodeOffset="-1" on the > SitemapDataSource and set the number of static menu levels to 3 on the > menu. However, this ends up displaying the children of all the > siblings as well (which makes the menu much too large). > > Ideas? > > Thanks, > Clint > > That's awesome Kelly. Thank you!
I just need to figure out how to encapsulate that with a master page. Any ideas where to start? The best I can come up with is to put this in a subclass of Page that all my pages inherit from. Thanks again, Clint
Push Button Event in datagrid
FileUpload, Wizard, and saving the data Web Standards Compliance - Autopostback / Javascript off access control in a Repeater from javascript Wizard, goto page, need to set values of a control in a Repeater Set file extensions for FileUpload delete rows in dataset Custom Web Control and Default Height/Width Dynamic Menu Control in ASP.NET2 User Control question - REPOSTED |
|||||||||||||||||||||||