Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

VB.NET checked List Box validation

I am writing a simple data entry form and want to use the checked list box. Each box may have more than 2 items in the collection but only one should be selectable at a time. This value should also update the bound SQL server field with the name of the item selected from the collection. I need help with the syntax to make this happen!

what I have so far:

Private Sub clbDeadorAlive_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clbDeadorAlive.ItemCheck

End Sub

Dead or Alive being the items in the collection, There are also CLB's with 4 or more items in the collection.

0
Dalexan
Asked:
Dalexan
  • 2
1 Solution
 
mmarinovCommented:
Why don't you use RadioButtonList
if you choose that the only thing that you will have to do is to check if the an item of this list is selected
this could be done by two ways
use RequireFieldValidator and set it's property ControlToValidate to this list
you can write your own validator in your page_load

B..G
0
 
DalexanAuthor Commented:
Can you type out the syntax for the RadioButtonList control.
0
 
mmarinovCommented:
if you will bind the radiobuttonlist from your code behind

Dim rbList as RadiobuttonList
rbList.DataSource = yourdataset
rbListDataTextField = yourcolumnfromyourdataset
rbListDataValueField = yourcolumnfromyourdataset
rbList.DataBind()

this will bind a dataset to your radiobuttonlist

the add to your form
Dim reqValid as RequiredFieldValidator
reqValid.ControlToValidate = rbList;
reqValid.EnableClientScript = True

this will give you that if you not select an item from the radiobuttonlist the form will not be submited

if you will add these controls in design mode
from the tool box drag and drop Radiobuttonlist object to your form
in Properties window of this web control define DataSource , rbListDataTextField and rbListDataValueField

after that drag and drop RequiredFieldValidator web control and in the properties window set ControlToValidate to the radiobuttonlist id

B..G
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now