A
Alan Silver
Hello,
I have a repeater with a list of products in it. Each item in the
repeater has a checkbox, allowing the product to be selected. When a
link button is clicked, I want to loop through the repeater and handle
each product whose checkbox is checked.
The repeater looks (greatly chopped down) like this...
<asp:Repeater ID="rptProducts" RunAt="Server">
<ItemTemplate>
<li><asp:CheckBox ID="chkDelete" RunAt="server"/>
<%#DataBinder.Eval(Container.DataItem, "PName")%>
</ItemTemplate>
</asp:Repeater>
and the code for the link button looks like...
void lbtDeleteProducts_Click(object o, EventArgs e) {
for (int i=0; i<rptProducts.Items.Count; i++) {
if (((CheckBox)rptProducts.Items.FindControl("chkDelete")).Checked) {
// do stuff here
}
}
}
The problem is that the loop works fine for the first product checked,
but not for any others. The weird thing is that this code is pretty much
identical to code I have used elsewhere that works fine. I can' see why
this only picks up the first checked checkbox. Anyone any idea why?
TIA
I have a repeater with a list of products in it. Each item in the
repeater has a checkbox, allowing the product to be selected. When a
link button is clicked, I want to loop through the repeater and handle
each product whose checkbox is checked.
The repeater looks (greatly chopped down) like this...
<asp:Repeater ID="rptProducts" RunAt="Server">
<ItemTemplate>
<li><asp:CheckBox ID="chkDelete" RunAt="server"/>
<%#DataBinder.Eval(Container.DataItem, "PName")%>
</ItemTemplate>
</asp:Repeater>
and the code for the link button looks like...
void lbtDeleteProducts_Click(object o, EventArgs e) {
for (int i=0; i<rptProducts.Items.Count; i++) {
if (((CheckBox)rptProducts.Items.FindControl("chkDelete")).Checked) {
// do stuff here
}
}
}
The problem is that the loop works fine for the first product checked,
but not for any others. The weird thing is that this code is pretty much
identical to code I have used elsewhere that works fine. I can' see why
this only picks up the first checked checkbox. Anyone any idea why?
TIA