danjonescidtrix danjonescidtrix - 1 month ago 12
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">
</asp:CheckBoxList>


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


"1,2,3,4,5,6,7,8,9,10"


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(",")
Next


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

Answer

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))
Next
Comments