|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Items.Count command
i have a databoud checkbox that can return anywhere from 1 to server HUNDRED checkboxes depending on what a user selects from a drop down list. my question is this, everytime i try to find out how many controls were returned, it comes back with 0
i use CheckBoxList1.Items.Count is there a different sytex i should be using for data bound controls? |
|
#2
|
||||
|
||||
|
Hi,
I dont know if this is a bit clunky but you could loop through all of the controls on your form counting the number of checkboxes as you go: Code:
Private Sub Form_Load()
Label1.Caption = CountChecks
End Sub
Private Function CountChecks() As Integer
CountChecks = 0
For Each Control In Me.Controls
If TypeOf Control Is CheckBox Then
CountChecks = CountChecks + 1
End If
Next
End Function
|
|
#3
|
|||
|
|||
|
wouldnt work, i have a bunch of other check boxes that i'm not interested in counting, only this one. any other ideas?
|
|
#4
|
||||
|
||||
|
Quote:
The only other suggestion I can make is that you could adjust your naming convention, maybe prefix the ones that you want to ignore with a certain string and only count the ckeckboxes whose names dont start with that string. For example, if you name all of the checkboxes on your form "ckb" followed by a unique ID, you can only count the dynamically created checkboxes: Code:
Dim myControl As Control
For Each myControl In Me.Controls
If TypeOf myControl Is CheckBox Then
If Left(myControl.Name, 3) <> "ckb" Then countchecks = countchecks + 1
End If
Next
|
|
#5
|
|||
|
|||
|
will that work if i have another 2 databound checkboxes though?
|
|
#6
|
||||
|
||||
|
Quote:
I dont know I'm sorry, I was just trying to give you some ideas, but I would have thought that as long as you stick to a certain naming convention you should be able to only count the ones you want. |
|
#7
|
||||
|
||||
|
CheckBoxList1.Items.Count will return the items count.
it works. the problem is elsewhere, post your code and we'll try to help you locate and fix the real problem. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Items.Count command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|