CheckBoxList

Properties ofCheckBoxList
Property |
Description |
CellPadding |
Between border and contents of the cell |
CellSpacing |
Distance between cells |
RepeatColumns |
How many columns to display in checkboxlist control |
RepeatDirection |
Vertical or Horizontal |
RepeatLayout |
Flow or Layout(default) |
TextAlign |
Left or Right |

Bind checkBoxList to an Array
- Open Visual Studio
- Add a new webform call it check1.aspx

- Type Pick your favorite Munster:
- Drag a checkBoxList control to the page
- Name it chkMunster
- Double-click the page and add this code in the page_load:
dim Munsters=New ArrayList Munsters.Add("Herman") Munsters.Add("Lily") Munsters.Add("Grandpa") Munsters.Add("Eddie") Munsters.Add("Marylyn") Munsters.TrimToSize() if Not Page.IsPostBack then chkMunsterList.DataSource= Munsters dataBind() end if

Now Let’s add additional code to change how the checkboxlist displays:
- Add a checkbox control
- Name it chkMode
- Set text to Display Vertically
- Set checked to true
- Set autopostback to true
- Double-click the checkbox and add this code:
If chkMode.checked then
chkMunsterList.RepeatDirection=RepeatDirection.Vertical
else
chkMunsterList.RepeatDirection=RepeatDirection.horizontal
end if




Display selected items from the list when the button is clicked
- Add a label control name it lblDisplay
- Add a button control
- Double-click the button
Add this code to the button click event:
Dim labelString="You Selected:<br />" Dim myCount as Integer for myCount=0 to chkMunsterList.Items.Count-1 if chkMunsterList.Items(myCount).Selected then labelString+=chkMunsterList.Items(myCount).Text labelString+="<br />" end if next lblDisplay.text=labelString

