/// <summary> /// Recursively binds a /// </summary> /// <param name="list"></param> /// <param name="node"></param> private void RecursiveMenuBind(MenuList list, XmlNode node) { // Only bind Element nodes, not comments if (pedc.IsDisplayInMainMenu(node) && pedc.IsDisplayInView(node) && node.NodeType == XmlNodeType.Element) { MenuListItem Item = GetFormattedListItem(node); list.Controls.Add(Item); if (node.HasChildNodes) { howdeep++; if (howdeep < DEPTH || DEPTH < 0) { MenuList SubMenu = new MenuList(); Item.Controls.Add(SubMenu); foreach (XmlNode child in node.ChildNodes) { RecursiveMenuBind(SubMenu, child); AddLinkStyle(SubMenu); } // Logic to set static heights and overflow // Need to set widths inline to prevent collapsing in som DOM browsers if (!string.IsNullOrEmpty(StaticHeight) && SubMenu.Controls.Count > 20) { SubMenu.Style.Add("height", StaticHeight + "px"); if (SubMenu.Controls[0] is MenuListItem) { if (SubMenu.Controls[0].HasControls()) { if (SubMenu.Controls[0].Controls[0] is HyperLink) { string width = ((HyperLink)SubMenu.Controls[0].Controls[0]).Style["width"]; if (!string.IsNullOrEmpty(width)) { string subMenuWidth = int.Parse(width.Replace("em", "")) + 2 + "em"; SubMenu.Style.Add("width", subMenuWidth); } } } } SubMenu.Style.Add("overflow", "auto"); } if (!SubMenu.HasControls() && SubMenu.Parent != null) { SubMenu.Parent.Controls.Remove(SubMenu); } } howdeep--; } } }
/// <summary> /// Wraps the XmlNode into a MenuListItem with inner controls /// </summary> /// <param name="node">Node to wrap as a MenuListItem</param> /// <returns></returns> public MenuListItem GetFormattedListItem(XmlNode node) { // Create base objects MenuListItem Item = new MenuListItem(); Literal ItemText = new Literal(); HyperLink ItemLink = new HyperLink(); Image itemImage = new Image(); itemImage.Visible = false; // Set default values ItemText.Text = GetDataBoundTextField(node); ItemLink.Text = GetDataBoundTextField(node); //ItemLink.NavigateUrl = "#"; MenuBinding ItemBinding = GetMenuBinding(node); if (ItemBinding != null) { //string[] OptFields = GetPopulatedFields(node); string href = XmlUtil.GetAttributeValue(node, "href"); if (!string.IsNullOrEmpty(href)) { ItemLink.NavigateUrl = href; } // Set the url for the hyperlink else if (ItemBinding.URL != null) { ItemLink.NavigateUrl = GetPopulatedField(node, ItemBinding.URL); } // If defined, set the URL Target string target = XmlUtil.GetAttributeValue(node, "target"); if (!string.IsNullOrEmpty(target)) { ItemLink.Target = target; } else if (ItemBinding.URLTarget != null) { ItemLink.Target = GetPopulatedField(node, ItemBinding.URLTarget); } string onclick = XmlUtil.GetAttributeValue(node, "onclick"); if (!string.IsNullOrEmpty(onclick)) { string ClientAction = onclick; ItemLink.Attributes.Add("onclick", ClientAction); } //Client click else if (ItemBinding.OnClientClick != null) { string ClientAction = GetPopulatedField(node, ItemBinding.OnClientClick); ItemLink.Attributes.Add("onclick", ClientAction); } // set icon string tableName = XmlUtil.GetAttributeValue(node, "tableName"); itemImage.Visible = false; if (!string.IsNullOrEmpty(tableName)) { string iconPath = pedc.GetTableIcon(tableName, true); if (!string.IsNullOrEmpty(iconPath)) { itemImage.ImageUrl = iconPath; itemImage.CssClass = "MenuItemIcon"; itemImage.Visible = true; } } } // Combine the controls to produce MenuListItem ItemLink.Controls.Add(itemImage); ItemLink.Controls.Add(ItemText); Item.Controls.Add(ItemLink); return(Item); }