private void RemoveSelectedNodes(ref WebSiteNode root) { List <WebSiteNode> selected = root.Children.Where(n => n.Selected == true).ToList <WebSiteNode>(); foreach (WebSiteNode item in selected) { root.FindById(item.Id).Selected = false; /* * if (item.HasChildren()) * { * RemoveSelectedNodes(ref item); * } */ } }
protected override void OnPreRender(EventArgs e) { try { base.OnPreRender(e); dataSource = this.GetDataSource() as WebSiteDataSource; provider = (dataSource != null) ? dataSource.Provider : null; if (provider == null) { return; } menu = MenuBase.Instantiate(ClientID, ControlType, ControlStyle); menu.ApplySettings( new Settings { ControlType = ControlType, ControlStyle = ControlStyle, NodeXmlPath = NodeXmlPath, NodeSelector = NodeSelector, IncludeContext = IncludeContext, IncludeHidden = IncludeHidden, IncludeNodes = IncludeNodes, ExcludeNodes = ExcludeNodes, NodeManipulator = NodeManipulator, ClientOptions = ClientOptions, TemplateArguments = TemplateArguments }); Uri url = WebSiteControllerModule.GetFullUrl(Context); SPSite site = new SPSite(url.OriginalString); bool isControlled = false; CheckUrlOnZones(site, url, out url, out isControlled); List <WebSiteNode> nodes = new List <WebSiteNode>(); if (isControlled) { WebSiteNode cnode = provider.FindWebSiteNode(url.ToString()); if (cnode != null) { nodes.Add(cnode); } } if (nodes.Count == 0) { List <SemanticUrl> entries = CheckForManagedUrl(site, url); foreach (SemanticUrl surl in entries) { WebSiteNode cnode = provider.FindWebSiteNode(surl.Semantic); if (cnode != null) { nodes.Add(cnode); } } //urlnode = provider.FindWebSiteNode(Context.Request.Url.ToString()); } WebSiteNode root = (WebSiteNode)provider.RootNode.Clone(); if (provider.CurrentNode != null) { root.FindById(provider.CurrentNode.Id).Selected = false; } else { RemoveSelectedNodes(ref root); } if (nodes.Count > 0)// != null) { foreach (WebSiteNode node in nodes) { root.FindById(node.Id).Selected = true; } /* * if (nodes.Count == 1) * { * root.CurrentNode = nodes[0]; * } */ } else { root.Selected = true; } //provider.ResetProvider(); menu.RootNode = root;// provider.RootNode; menu.PreRender(this.Page); } catch (Exception exc) { exc.ToString(); } }