• ASP.NET Repeater嵌套Repeater实现菜单加载


                在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();
                 
                }
            }
        }


     

  • 相关阅读:
    CentOS/Linux安装VNCserver
    vncserver的安装和使用
    linux下常用FTP命令 1. 连接ftp服务器
    linux下安装dovecot
    教你如何架设linux邮件服务器postfix
    vim打开文件时显示行号
    VirtualBox 配置虚拟网卡(桥接),实现主机-虚拟机网络互通
    Linux文件权限详解
    虚拟机下CentOS 6.5配置IP地址的三种方法
    Linux基础知识之man手册的使用
  • 原文地址:https://www.cnblogs.com/james1207/p/3424263.html
Copyright © 2020-2023  润新知