danjonescidtrix danjonescidtrix - 1 year ago 127
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.

Answer Source

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))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download