Asp.Net Repeater的两层嵌套以及遍历取值的简单实现
2020-03-01 15:17
1146 查看
<select id="s6" multiple="multiple">
<asp:Repeater ID="rpl_dept" runat="server"
onitemdatabound="rpl_dept_ItemDataBound">
<ItemTemplate>
<optgroup label="<%#Eval("Name") %>">
<asp:Repeater ID="rpl_user" runat="server">
<ItemTemplate>
<option><%#Eval("Name")%></option>
</ItemTemplate>
</asp:Repeater>
</optgroup>
</ItemTemplate>
</asp:Repeater>
</select>
protected void rpl_bind()
{
com.hmby.BLL.Depts dept = new com.hmby.BLL.Depts();
string strWhere = "";
DataTable dt = new DataTable();
dt = dept.GetList(strWhere).Tables[0];
if (dt.Rows.Count > 0)
{
this.rpl_dept.DataSource = dt;
this.rpl_dept.DataBind();
}
}
protected void rpl_dept_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("rpl_user") as Repeater;//找到里层的repeater对象
DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项
int deptId = Convert.ToInt32(rowv["Id"]); //获取填充子类的id
DataTable dt = new DataTable();
com.hmby.BLL.Users user = new com.hmby.BLL.Users();
string strWhere = " DeptId=" + deptId;
dt = user.GetList(strWhere).Tables[0]; ;
if (dt.Rows.Count > 0)
{
rep.DataSource = dt;
rep.DataBind();
}
}
}
另外一种嵌套的前台(表格)(下边是遍历)
<asp:Repeater ID="rpl_mParent" runat="server"onitemdatabound="rpl_mParent_ItemDataBound">
<ItemTemplate>
<tr>
<td style="vertical-align:top;background-color:#ffa !important;">
<input type="checkbox" id="cbox_p" value='<%# Eval("Id")%>' runat="server"/>
<label class="choice" for="cb1"><%# Eval("ModelName")%></label>
</td>
</tr>
<asp:Repeater ID="rpl_mChild" runat="server">
<ItemTemplate>
<tr><td>
<input type="checkbox" id="cbox_c" value='<%# Eval("Id")%>' runat="server"/>
<label class="choice" for="cb1"><%# Eval("ModelName")%></label>
</td></tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
遍历嵌套的Checkbox,双层遍历
for (int i=0;i<this.rpl_mParent.Items.Count;i++)
{
HtmlInputCheckBox cbox_p = (HtmlInputCheckBox)rpl_mParent.Items[i].FindControl("cbox_p");
if (cbox_p.Checked)
{
//选中了checkbox_p
JsUtil.Alert(this, "p");
}
Repeater rplChild = (Repeater)rpl_mParent.Items[i].FindControl("rpl_mChild");
string c = "";
for (int j=0;j<rplChild.Items.Count;j++)
{
HtmlInputCheckBox cbox_c = (HtmlInputCheckBox)rplChild.Items[j].FindControl("cbox_c");
if (cbox_c.Checked)
{
//选中了checkbox_c
c += cbox_c.Value + ",";
}
}
JsUtil.Alert(this, c);
}
转载于:https://www.cnblogs.com/mushaobai/archive/2011/12/27/2303660.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Asp.Net Repeater的两层嵌套以及遍历取值的简单实现
- Asp.Net Repeater的两层嵌套以及遍历取值的简单实现(checkbox)
- ASP.NET中repeater嵌套实现代码(附源码)
- asp.net中repeater控件的嵌套和实现分页
- ASP.NET中repeater嵌套实现代码(附源码)
- 如何应用Asp.Net Mvc内建功能(DefaultModelBinder)实现简单类型、复杂类型、集合类型,以及字典类型的自动绑定
- asp.net实现DataList与Repeater嵌套绑定的方法
- asp.net实现DataList与Repeater嵌套绑定的方法
- Asp.net中创建程序集以及一个简单的IHttpHandler 实现
- ASP.NET Repeater控件实现简单分页
- ASP.NET中JSONP的两种实现以及其他跨域解决方案的简单实现
- C#实现多级子目录Zip压缩解压实例 NET4.6下的UTC时间转换 [译]ASP.NET Core Web API 中使用Oracle数据库和Dapper看这篇就够了 asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程 asp.net core异步进行新增操作并且需要判断某些字段是否重复的三种解决方案 .NET Core开发日志
- ASP.NET MVC登录实现Cookie加密以及过滤器简单使用
- 单点登录在ASP.NET上的简单实现
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI
- asp.net实现在网页上自动显示超链接以及Email地址
- Asp.net RBAC membership framework 中RBAC的具体实现,以及发布前的一些话
- 将Asp.net从VS2003以及VS2002工程转换为VS2005工程的简单而又行之有效的方法
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI。
- 单点登录在ASP.NET上的简单实现