[英]How to calculate how many checkboxes are checked in VB.Net
我有3個asp.net標准復選框控件和1個文本框。 我選中1和3復選框。 在文本框中如何計算選中了多少個復選框? 如果選中1,則文本框結果為1。如果選中1,2,則文本框結果為2。如果選中所有復選框,則結果為3
如何在vb.net中做到這一點?
Dim count As Integer
count = 0
If checkbox1.Checked Then
count = count + 1
End If
If checkbox2.Checked Then
count = count + 1
End If
If checkbox3.Checked Then
count = count + 1
End If
textbox1.Text = count.ToString()
如果要檢查多個控件,請使用(我正在修改@Nick代碼):
Dim count As Integer
count = 0
For Each ctrl As Control In Page.Controls
If TypeOf ctrl Is CheckBox Then
If CType(Control, CheckBox).Checked Then
count=count+1
End If
End If
Next
textbox1.Text = count.ToString()
textbox1.Text = IIf(checkbox1.Checked, 1, 0) + IIf(checkbox2.Checked, 1, 0) + IIf(checkbox3.Checked, 1, 0)
我尚未檢查此作品,但請嘗試:
暗淡計數為整數
計數= 0
For Each ctrl As Control In Page.Controls
If TypeOf ctrl Is Checkbox Then
count=count+1
End If
Next
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.