How to Use the CheckBoxList Control in Visual Basic.NET
In this tutorial you will learn how to use the CheckBoxList control in Visual Basic.NET. The CheckBoxList control is used to create a multi-selection check box group. It can be used on many applications ranging from job applications to surveys, the CheckBoxList control is a flexible tool that can be used on may web sites. In this tutorial we will use a CheckBoxList to list video game systems and allow the user to select the systems they own.
Setting Up
If you have not done so already, open Visual Studio and create a new web site. Name the web site CheckBoxListControl and add a web form named Default.aspx.
Step One
In the open div tags, enter the question “What systems do you own?” and place a CheckBoxList control below it. Add the items with the ListItem template into the CheckBoxList as shown in the code snippet below.
Change the properties of the Literal and ListBox controls to match those above. Setting the ‘Visible’ attribute to false allows the text to be invisible until the button is clicked.
Step Two
Now switch to design view and double click the ‘Submit’ button to create an event handler for it. In the code behind page you will see a Button1_Click event method, this is where we will enter code to display the selections of the user. Since we changed the Literal and ListBox controls to be invisible, we will set them to visible on button click. We then clear all previous items in the ListBox so there are no duplicates when the button is clicked again. We will then create a ListItem variable that will loop through the items in the CheckBoxList and add them to the ListBox.
Output
Run the page and you will see the consoles we put into our CheckBoxList. In our case, we will select ‘Sony Playstation 3′, ‘Microsoft Xbox 360′, and ‘Nintendo Wii’ and they will appear in a ListBox.

Thanks for reading and make sure to download the source files to get a better understanding of how the code works.
CheckBoxListControl-VB.zip
Setting Up
If you have not done so already, open Visual Studio and create a new web site. Name the web site CheckBoxListControl and add a web form named Default.aspx.
Step One
In the open div tags, enter the question “What systems do you own?” and place a CheckBoxList control below it. Add the items with the ListItem template into the CheckBoxList as shown in the code snippet below.
Code Block
Default.aspx
CheckBoxList Control.What systems do you own?
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>Sony Playstation 3</asp:ListItem>
<asp:ListItem>Sony Playstation Portable</asp:ListItem>
<asp:ListItem>Microsoft Xbox 360</asp:ListItem>
<asp:ListItem>Nintendo Wii</asp:ListItem>
<asp:ListItem>Nintendo DS</asp:ListItem>
</asp:CheckBoxList>
We stand behind Server Intellect and their support team. They offer dedicated servers, and they are now offering cloud hosting!
Now place a Button control below the closing CheckBoxList tag and change the text to Submit. Add a Literal and ListBox control below the button control.Code Block
Default.aspx
Add the items from the Toolbox.
<asp:Button ID="Button1" runat="server" Text="Submit" />
<br />
<asp:Literal ID="Literal1" runat="server" Text="You own:" Visible="False"></asp:Literal>
<br />
<asp:ListBox ID="ListBox1" runat="server" Visible="False"></asp:ListBox>
Step Two
Now switch to design view and double click the ‘Submit’ button to create an event handler for it. In the code behind page you will see a Button1_Click event method, this is where we will enter code to display the selections of the user. Since we changed the Literal and ListBox controls to be invisible, we will set them to visible on button click. We then clear all previous items in the ListBox so there are no duplicates when the button is clicked again. We will then create a ListItem variable that will loop through the items in the CheckBoxList and add them to the ListBox.
Code Block
Default.aspx.vb
Output the user’s selections.Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Literal1.Visible = True
ListBox1.Visible = True
ListBox1.Items.Clear()
Dim item As ListItem
For Each item In CheckBoxList1.Items
If item.Selected Then
ListBox1.Items.Add(item.ToString())
End If
Next
End Sub
Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!
We add the items selected in CheckBoxList1 and use the Add method to add them to ListBox1.Output
Run the page and you will see the consoles we put into our CheckBoxList. In our case, we will select ‘Sony Playstation 3′, ‘Microsoft Xbox 360′, and ‘Nintendo Wii’ and they will appear in a ListBox.
Thanks for reading and make sure to download the source files to get a better understanding of how the code works.
CheckBoxListControl-VB.zip
