CheckBoxList

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.
 
S

S. Justin Gengo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top