我有这段代码,需要知道在
背后的代码中选择了哪些复选框任何人都可以帮助我吗?
<asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="ParentRepeater_ItemDataBound">
<ItemTemplate>
<label>
<%# Eval("TeacherName")%>
</label>
<br />
<asp:Repeater ID="ChildRepeater" runat="server">
<ItemTemplate>
<label>
<input type="checkbox" id="students" runat="server" /><%# Eval("StudentName")%>
</label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
答案 0 :(得分:1)
ParentRepeater
项目For each item as repeateritem in ParentRepeater.Items For each item2 as repeateritem in ctype(item.findcontrol("ChildRepeater"),repeater).items if ctype(item2.findcontrol("students"),checkbox) response.write(ctype("ltlStudentName"),literal).text) end if next Next
将标记的一行更改为:
<input type="checkbox" id="foods" runat="server" /><asp:literal id="ltlStudentName" runat="server" text='<%# Eval("StudentName")%>' />
答案 1 :(得分:0)
这是最后一次尝试解决和所有checkbox.Checked不会改变所有相等的错误
foreach (RepeaterItem item in ParentRepeater.Items)
{
Repeater rep = ((Repeater)item.FindControl("ChildRepeater"));
foreach (RepeaterItem item2 in rep.Items)
{
var chkBox = item2.FindControl("students") as HtmlInputCheckBox;
}
}
<asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="ParentRepeater_ItemDataBound">
<ItemTemplate>
<label>
<%# Eval("TeacherName")%>
</label>
<br />
<asp:Repeater ID="ChildRepeater" runat="server">
<ItemTemplate>
<label>
<input type="checkbox" id="students" runat="server" /><asp:literal id="ltlStudentName" runat="server" text='<%# Eval("StudentName")%>' />
</label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>