Reputation: 53
I have this code and need to know which checkboxes are selected in code behind
Can anyone help me ?
<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>
Upvotes: 1
Views: 6109
Reputation: 53
this is the last try to solve and all checkbox.Checked not change all equal false
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>
Upvotes: 0
Reputation: 103348
ParentRepeater
itemsFor 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
And change one line of your markup to:
<input type="checkbox" id="foods" runat="server" /><asp:literal id="ltlStudentName" runat="server" text='<%# Eval("StudentName")%>' />
Upvotes: 1