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>
||||
||||
主要代码如下:
<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(); } } }
相关文章推荐
- ASP.NET MVC 3 and the @helper syntax within Razor
- 给树莓派2的vim安装powerline时遇到的一些小问题和解决方法
- asp.net中利用NPOI导出数据到excel中
- asp.net中DataTable和List<T>之间相互转换
- 七天学会ASP.NET MVC (四)——用户授权认证问题
- 【ASP.NET】ADO.NET
- Asp.NET开启一个线程,不停的执行
- ASP.NET中处理自定义错误的最佳方式
- IIS经典模式对ASP.NET MVC应用程序的影响
- ASP.NET Web API 跨域访问(CORS)要注意的地方
- asp.net 后台弹框,过一定时间跳到另外一个页面
- asp.net给邮箱发送邮件
- 使用aspose.word两句代码将word转换为pdf
- 用Jasper report计算opening balance
- asp.NET
- Asp.Net实现在线网站安装(上)
- 如何在ASP.NET MVC为Action定义筛选器
- Asp.net 页面访问模板页的属性
- ASP 500错误解决方法
- Asp.net MVC 2 中解决页面提交数据并发问题