您的位置:首页 > 编程语言 > ASP

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

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


||||


||||


主要代码如下:
<table id="table1" class="grid" singleselect="true">
<thead>
<tr>
<td style="width: 40px; text-align: left;">
<label id="checkAllOff" onclick="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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: