Checkbox and repeater

S

simon

I have datarepeater with checkBox:
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"adv_name") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"adv_start") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"adv_end") %></td>
<td align="center">
<asp:CheckBox Runat="server" ID='chkPList'></asp:CheckBox>
</td>
</tr>
</ItemTemplate>

I would like to set the ID of checkBox dynamic:

Private Sub rprPlists_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
rprPlists.ItemDataBound

If (e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.Item) Then

Dim chkBox As CheckBox
chkBox = e.Item.FindControl("chkPList")
chkBox.ID = e.Item.DataItem(0).ToString() 'for example: "111"

End If

End Sub

It works, now I have checkBox with desired ID.

When user click the submit, I would like to check, which checkBoxes are
clicked and then read it's ID.

Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOk.Click

Dim i As Integer
Dim chkBox As CheckBox
Dim ID as string

For i = 0 To rprPlists.Items.Count - 1
chkBox = CType(rprPlists.Items(i).FindControl("chkPlist"), CheckBox)
if chkBox.checked=true then
id=chkBox.ID
end if
Next

End Sub

This works, I get the checkBox

When I read it's ID, I get the value: "chkPList" instead of desired ID
("111"), which was set on ItemDataBound.
Why? How can I read the right ID?

Thank you,
Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top