danjonescidtrix danjonescidtrix - 5 days ago 4x
Vb.net Question

Vb.net create checkbox items from comma delimited string

I have a simple ASP checkbox list (see bellow):

<asp:CheckBoxList ID="CheckBoxList1" runat="server">

I have a string in my vb.net (see bellow):


I want to be able to loop through each number in my string and add each one as a checkbox in my checkbox list. I have searched online though most solutions I have come across seem slightly different from what I want to achieve.

This is the code I have so far:

For Each s In checkBoxString.split(",")

I was wondering if anyone could give me any suggestions to how I can achieve this. Any help is appreciated, Thank you in advance.


You need to create a ListItem and add it to the list of CheckBoxList items:

For Each s In checkBoxString.split(",")
    CheckBoxList1.Items.Add(New ListItem(s))