提交后如何遍历Repeater 中的 CheckBox ????

kamengwang 2008-11-07 11:45:00
......

<tr>
<td bgcolor="#F4F4F4" style="height: 25px" colspan="4">
<asp:Repeater ID="oneList" runat="server" OnItemDataBound="OneList_ItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
</HeaderTemplate>
<ItemTemplate>
<td valign="top">
<strong><font color="#FF0000">⊙ <%# DataBinder.Eval(Container.DataItem,"title")%></font></strong>
<asp:Label ID="oneId" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"id") %>'
Visible="false"></asp:Label>
<asp:Repeater ID="towList" runat="server">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="4%" height="22">
  </td>
<td width="96%" colspan="2">
<asp:CheckBox ID="chkId" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"id") %>'>
</asp:CheckBox>
<font color="#000099"><strong>
<%# DataBinder.Eval(Container.DataItem,"title")%>
</strong></font>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
</td>
</ItemTemplate>
<FooterTemplate>
</tr> </table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
<tr>
<td height="30" colspan="4" align="center" bgcolor="#F4F4F4">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text=" 保 存 " OnClientClick="return ChkKeys();" />
    <input id="Reset1" type="reset" value=" 重 填 " />
</td>
</tr>

......
...全文
313 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
搬砖de蚂蚁 2008-11-07
  • 打赏
  • 举报
回复
foreach (Control ctl in Repeater1.Controls)
{
if (ctl is CheckBox)
{
(ctl as CheckBox).Checked = true;
}
}
claymore1114 2008-11-07
  • 打赏
  • 举报
回复
foreach (Control c in this.Repeater1.Controls)
{

CheckBox check = (CheckBox)c.FindControl("cbDelete1");
if( check != null )
{
check.Checked = true;
}
}

mjjzg 2008-11-07
  • 打赏
  • 举报
回复
楼上的难道不可以吗
antiking 2008-11-07
  • 打赏
  • 举报
回复
foreach (Control ctl in Repeater1.Controls)
{
if (ctl is CheckBox)
{
(ctl as CheckBox).Checked = true;
}
}
kamengwang 2008-11-07
  • 打赏
  • 举报
回复
<tr>
<td bgcolor="#F4F4F4" style="height: 25px" colspan="4">
<asp:Repeater ID="oneList" runat="server" OnItemDataBound="OneList_ItemDataBound">
<HeaderTemplate>
.....................................................
</HeaderTemplate>
<ItemTemplate>
............................................................
<asp:Repeater ID="towList" runat="server">
<HeaderTemplate>
.............................................
</HeaderTemplate>
<ItemTemplate>
<tr>
...............................
<asp:CheckBox ID="chkId" runat="server" Text=' <%#DataBinder.Eval(Container.DataItem,"id") %>'>
</asp:CheckBox>
....................
</tr>
</ItemTemplate>
<FooterTemplate>
.......................................... </FooterTemplate>
</asp:Repeater>
</td>
</ItemTemplate>
<FooterTemplate>
</tr> </table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
<tr>
<td height="30" colspan="4" align="center" bgcolor="#F4F4F4">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text=" 保 存 " OnClientClick="return ChkKeys();" />
     <input id="Reset1" type="reset" value=" 重 填 " />
</td>
</tr>



简化一下,是嵌套的Repeater.
jack20080808 2008-11-07
  • 打赏
  • 举报
回复

for (int i = 0; i < rptFriend.Items.Count; i++)
{
if ((rptFriend.Items[i].FindControl("chkId") as CheckBox).Checked)
{

}
}
jack20080808 2008-11-07
  • 打赏
  • 举报
回复
        for (int i = 0; i < oneList; i++)
{
if ((oneList.Items[i].FindControl("chkId") as CheckBox).Checked)
{

}
}
kamengwang 2008-11-07
  • 打赏
  • 举报
回复
说实话

foreach (Control ctl in Repeater1.Controls)
{
if (ctl is CheckBox)
{
(ctl as CheckBox).Checked = true;
}
}



foreach (Control c in this.Repeater1.Controls)
{

CheckBox check = (CheckBox)c.FindControl("cbDelete1");
if( check != null )
{
check.Checked = true;
}
}

还真是不行,我按照"jack20080808"给的这个

for (int i = 0; i < rptFriend.Items.Count; i++)
{
if ((rptFriend.Items[i].FindControl("chkId") as CheckBox).Checked)
{

}
}

自己改造里一个,绝对没问题了,

for (int i = 0; i < oneList.Items.Count; i++)
{
Repeater ListTow = (Repeater)oneList.Items[i].FindControl("towList");

foreach (RepeaterItem item in ListTow.Items)
{
CheckBox chkbox1 = (CheckBox)item.FindControl("chkId");
if (chkbox1.Checked == true)
strWhere = strWhere + chkbox1.Text.ToString() + ",";
}
}

YOLO高分设计资源源码,详情请查看资源内容使用说明 YOLO高分设计资源源码,详情请查看资源内容使用说明 YOLO高分设计资源源码,详情请查看资源内容使用说明 YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧