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.

What systems do you own?

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.

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.

We add the items selected in CheckBoxList1 and use the Add method to add them to ListBox1.


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.

checkboxlist 1

Thanks for reading and make sure to download the source files to get a better understanding of how the code works.

Download Source Files