【发布时间】:2014-03-26 08:13:07
【问题描述】:
我有 3 个 asp.net 标准复选框控件和 1 个文本框。我检查了 1 和 3 复选框。在文本框中如何计算有多少复选框被选中?如果我选中 1,则文本框结果为 1。如果我选中 1,2,则文本框结果为 2。如果我选中所有复选框,则结果为 3
如何在 vb.net 中做到这一点?
【问题讨论】:
标签: asp.net vb.net checkbox textbox
我有 3 个 asp.net 标准复选框控件和 1 个文本框。我检查了 1 和 3 复选框。在文本框中如何计算有多少复选框被选中?如果我选中 1,则文本框结果为 1。如果我选中 1,2,则文本框结果为 2。如果我选中所有复选框,则结果为 3
如何在 vb.net 中做到这一点?
【问题讨论】:
标签: asp.net vb.net checkbox textbox
textbox1.Text = IIf(checkbox1.Checked, 1, 0) + IIf(checkbox2.Checked, 1, 0) + IIf(checkbox3.Checked, 1, 0)
【讨论】:
我还没有检查过这个工作,但试试:
dim count as integer
计数 = 0
For Each ctrl As Control In Page.Controls
If TypeOf ctrl Is Checkbox Then
count=count+1
End If
Next
【讨论】:
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()
【讨论】: