CheckBoxList

  • Thread starter Thread starter jase_rw
  • Start date Start date
J

jase_rw

Hi There,

Having trouble with a CheckBoxList in VB.NET.

I've a CheckBoxList on a webform. I read some data from a database and
try and check the appropriate boxes based on the data. Unfortunately,
the CheckBoxList seems to behave like a RadioButtonList and only leaves
the last item checked.

I've even tried just to hard code 2 boxes being checked and that just
seems to check the last box only too.

CBL_AnswerOptions.SelectedIndex = 1
CBL_AnswerOptions.SelectedIndex = 3

The above leaves just box 3 checked.

Can anyone tell me what I'm doing wrong?

Thanks!!

Jason.
 
Jason,

You have to loop through the checkboxes and set each one that matches your
database data to true. Setting a selected value or selectedindex sets just
that one checkbox to selected and all others to unselected (as you've
found).

When you loop through each checkbox item do something like this:

For Each Item As ListItem In CheckBoxList.Items

If (SomeCheckHere) Then

Item.Selected = True

End If

Next


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Back
Top