在KS系统中要实现从数据库中读取界面权限文件实现菜单、界面的动态加载。
效果图:
ASP.NET界面代码
<div id="menu-container"> <asp:Repeater ID="rpMenu" runat="server" onitemdatabound="rpMenu_ItemDataBound"> <ItemTemplate> <div class="menu-tit" id="MenuName"> <asp:HiddenField ID="hfMenuID" runat="server" Value='<%#Eval("Id") %>' /> <%#Eval("MenuName") %></div> <div class="menu-list"> <div class="top-line"> </div> <ul class="nav-items"> <asp:Repeater ID="rpWindows" runat="server"> <ItemTemplate> <li><a href='<%#Eval("WindowsURL") %>' target="content" id="WindwosName"><%#Eval("WindowsName") %></a></li> </ItemTemplate> </asp:Repeater> </ul> </div> </ItemTemplate> </asp:Repeater> </div>
C#界面后台代码
public partial class AdmWelcom : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string strLike=""; DataBindMenu(strLike); } public void DataBindMenu(string strLike) { DataTable dtMenu= new DataTable(); AdmMenuManager admMenuManager = new AdmMenuManager(); //查询菜单 dtMenu = admMenuManager.QueryMenu(strLike); rpMenu.DataSource =dtMenu; rpMenu.DataBind(); } protected void rpMenu_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rpWindows = e.Item.FindControl("rpWindows") as Repeater; HiddenField hfMenuID=e.Item .FindControl ("hfMenuID") as HiddenField; DataTable dt = new DataTable(); string strLike = ""; BLL.AdmMenuManager admMenuManager = new AdmMenuManager(); string strMenuID = hfMenuID.Value.ToString().Trim() ; strLike = " TR_MenuWindows.MenuID='" + strMenuID + "'"; //查询界面下的窗体 dt = admMenuManager.QueryMenuWindows(strLike); rpWindows.DataSource = dt; rpWindows.DataBind(); } } }