Skip Navigation LinksASP.Net 2.0 Training : ASP.Net CheckBoxList
Banner for ASP.Net 2.0 training classes in Visual Basic 2005 

Skip Navigation Links
Visit my other site:

certification training

Free Flash tutorials and training

Free Dreamweaver Video Tutorials

Free PHP Training

Visual Basic Windows Training




If you like this site please link to it


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
  • Test it

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


      ASP.Net 2.0 tutorials & training