<ext:Region ID="regionLeft" Split="true" Width="200px" Margins="0 0 0 0" ShowHeader="true" Title="菜单" EnableCollapse="true" Layout="Fit" Position="Left" runat="server"> </ext:Region>
protected void Page_Init(object sender, EventArgs e) { InitMenu(); } private void InitMenu() { XMenuCollection menus = new Select().From<XMenu>() .Where(XMenu.ShowColumn).IsEqualTo(true) .OrderAsc(XMenu.SortIndexColumn.ColumnName) .ExecuteAsCollection<XMenuCollection>(); if (XConfigHelper.MenuType.ToLower() == "accordion") { // TODO 创建手风琴式菜单 } else { ExtAspNet.Tree tree = new ExtAspNet.Tree(); regionLeft.Items.Add(tree); tree.ShowBorder = false; tree.ShowHeader = false; tree.AutoScroll = true; tree.EnableArrows = true; ResolveMenuTree(menus, 0, tree.Nodes); } } /// <summary> /// 生成菜单树 /// </summary> /// <param name="menus"></param> /// <param name="parentMenuId"></param> /// <param name="nodes"></param> /// <returns>当前节点的子节点个数</returns> private int ResolveMenuTree(XMenuCollection menus, int parentMenuId, ExtAspNet.TreeNodeCollection nodes) { int count = 0; foreach (XMenu menu in menus) { if (menu.ParentMenuId == parentMenuId) { ExtAspNet.TreeNode node = new ExtAspNet.TreeNode(); nodes.Add(node); node.Text = menu.Name; node.IconUrl = menu.ImageUrl; if (!String.IsNullOrEmpty(menu.NavigateUrl)) { node.NavigateUrl = menu.NavigateUrl; node.Target = "main"; } int childCount = ResolveMenuTree(menus, menu.Id, node.Nodes); if (childCount == 0) { node.Leaf = true; } count++; } } return count; }
ExtAspNet.Accordion accordion = new ExtAspNet.Accordion(); regionLeft.Items.Add(accordion); accordion.ShowBorder = false; accordion.ShowHeader = false; foreach (XMenu menu in menus) { if (menu.ParentMenuId == 0) { ExtAspNet.AccordionPane pane = new ExtAspNet.AccordionPane(); accordion.Panes.Add(pane); pane.Title = menu.Name; pane.ShowBorder = false; ExtAspNet.Tree tree = new ExtAspNet.Tree(); pane.Items.Add(tree); tree.ShowBorder = false; tree.ShowHeader = false; tree.AutoScroll = true; tree.EnableArrows = true; ResolveMenuTree(menus, menu.Id, tree.Nodes); } }
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛