Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating CheckBoxList Control

Status
Not open for further replies.

AppzDev

MIS
Oct 9, 2002
57
US
I was wondering if anyone has any clean (i'd even take not so clean) method of updating a database when a checkboxlist has NO items selected. The page used to insert the data (using a sql insert into...) works just fine, however, when i try to update the database from an edit page (using a sql update...) i get an error that basically said i need to choose at least ONE of the checkbox's.

I pasted the code that takes the items selected in the checkboxlist, puts them into a string, and updates the database.

For each itmCADStatus in cblCADStatus.Items
If itmCADStatus.Selected Then
strCADStatus &=", " & itmCADStatus.Text
End If
Next

Thanks in advance.

dc.
 
Hmmm...isn't it the checked property and not selected that determines if the checkbox is checked?

D'Arcy
 
That could be too, i'll give that a try, however, i *think* i may have found a workaround...or maybe this is just "how you have to do it"

For each itmCADStatus in cblCADStatus.Items
If itmCADStatus.Selected Then
strCADStatus &=", " & itmCADStatus.Text
ElseIf strCADStatus = "" THEN
strCadStatus = ""
End If
Next

I added the
ElseIf strCADStatus = "" THEN
strCadStatus = ""
into the code and now the page processes without any errors and updates the database with basically, a blank.

What i'd like to know is why, on INSERTING data into a database using the "Insert Into.." (Using the code pasted on the original post) does it work when nothing is selected/checked, but UPDATING a database using the "Update..." does it error out when nothing is selected/checked?

If anyone has any explanation i'd be interested.

Thank You,
dc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top