一.Design
如果我们要实现的Web菜单不是动态的话,我们可以很方便的采用手动创建的方法。样式可以自己通过Css.css来样式化。
效果如: 2.是我要重要讲的:动态的如何来创建Web菜单: 所有的菜单都根据登陆者的权限来动态生成的。好了,不多说费话了。开始说如何来实现: using System; using ComponentArt.Web.UI; using WySysTemWeb.Components; using JH.WySystem.BLL.Admin; using JH.WySystem.BOL; using JH.WySystem.BOL.Admin; namespace WySysTemWeb { public partial class SysMenu :BasePage { protected ComponentArt.Web.UI.NavBar serverNavBar; protected ComponentArt.Web.UI.NavBar clientNavBar; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BuildServerNavBar(); } } private void BuildServerNavBar() { ComponentArt.Web.UI.NavBarItem newTopItem; ComponentArt.Web.UI.NavBarItem newItem; GenericCollection<SYS_T_Menu> menutree = SYS_T_MenuInfo.GetTopMenu(this.CurrentUser.User_ID); //Function_Menu menu = new Function_Menu(); foreach (SYS_T_Menu menu in menutree) { newTopItem = new ComponentArt.Web.UI.NavBarItem(); newTopItem.Text = menu.Menu_Name.ToString(); //父菜单左边的图标 // newTopItem.Look.LeftIconUrl = "right2.gif"; if (menu.Menu_ID == 1) { newTopItem.Expanded = true; } newTopItem.DefaultSubItemLookId = "Level2ItemLook"; //newTopItem.SubGroupCssClass = "Level2Group"; newTopItem.SelectedLookId = "TopItemLook"; serverNavBar.Items.Add(newTopItem); GenericCollection<SYS_T_Menu> menutreechild = SYS_T_MenuInfo.GetMenuByFatherID(menu.Menu_ID, this.CurrentUser.User_ID); foreach (SYS_T_Menu menuchild in menutreechild) { newItem = new NavBarItem(); newItem.Text = menuchild.Menu_Name.ToString(); newItem.Look.LeftIconUrl = menuchild.Menu_PictureUrl.ToString(); newItem.NavigateUrl = menuchild.Menu_PageUrl.ToString(); newTopItem.Items.Add(newItem); } } } } } 如有需要的朋友,我可以将我的完整代码E_mial给他,多多指点。
先说一下,我是在前一些的一个项目中,要实现下面的功能才研究的这个控件:现在那来和大家一起分享:效果如图