asp.net中Repeater中嵌套Repeater来显示跟外层Repeater数据相关的其他信息

        在实际开发中,比如在统一权限管理系统中,我们预先定义了一些列角色,我们点击每一个角色,进入一个应用系统列表,我们要知道每个应用系统中,该角色已经拥有多少菜单访问权限,我们就可以通过Repeater中嵌套Repeater来显示这些信息,如下图所示:


||

||


||

||


主要代码如下:

 <table id="table1" class="grid" singleselect="true">
                <thead>
                    <tr>
                        <td style="width: 40px; text-align: left;">
                            <label id="checkAllOff" οnclick="CheckAllLine()" title="全选">
                                 </label>
                        </td>
                        <td style="text-align: center;">应用系统名称
                        </td>
                        <td style="text-align: center;">应用系统地址
                        </td>
                        <td style="text-align: center;">角色权限分配情况
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="rp_Item" runat="server" OnItemDataBound="rp_Item_ItemDataBound">
                        <ItemTemplate>
                            <tr>
                                <td style="width: 40px; text-align: left;">
                                    <input type="checkbox" value="<%#Eval("System_ID")%>|<%#Eval("System_Name")%>" name="checkbox" />
                                </td>
                                <td style="text-align: center;">
                                    <%#Eval("System_Name")%>
                                </td>
                                <td style="text-align: center;">
                                    <%#Eval("System_Url")%>
                                </td>
                                <td style="text-align: center;">
                                    <asp:Repeater ID="rp_Use" runat="server">
                                        <ItemTemplate>
                                            <%#((AT.Web.ATBase.SysRole.cMsg)Container.DataItem).msg %>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            <% if (rp_Item != null)
                               {
                                   if (rp_Item.Items.Count == 0)
                                   {
                                       Response.Write("<tr><td colspan='4' style='color:red;text-align:center'>没有找到您要的相关数据!</td></tr>");
                                   }
                               } %>
                        </FooterTemplate>
                    </asp:Repeater>
                </tbody>
            </table>

 public string _Roles_Name;
        public string _key;
        private AT_System_IDAO system_idao = new AT_System_Dal();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this._Roles_Name = base.Server.UrlDecode(base.Request["Roles_Name"]);
                this._key = base.Request["key"];
                this.InitData();
            }
        }

        /// <summary>
        /// 初始化绑定列表数据
        /// </summary>
        private void InitData()
        {
            DataTable dt = this.system_idao.GetApplicationList();
            ControlBindHelper.BindRepeaterList(dt, this.rp_Item);
        }

        protected void rp_Item_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rpt2 = (System.Web.UI.WebControls.Repeater)e.Item.FindControl("rp_Use");
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到外层Repeater关联的数据项  
                string systemId = rowv["System_ID"].ToString();
                DataTable dtList = this.system_idao.GetMenuBindBySystemId(systemId);
                DataTable dtRoleRight = this.system_idao.InitRoleRight(this._key, systemId);
                string msg = "已分配<font color='blue'>" + dtRoleRight.Rows.Count + "</font>/共<font color='red'>" + dtList.Rows.Count + "</font>个菜单!";
                List<cMsg> result = new List<cMsg>();
                cMsg item = new cMsg();
                item.msg = msg;
                result.Add(item);

                if (result != null)
                {
                    rpt2.DataSource = result;
                    rpt2.DataBind();
                }
            }
        }



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值