如果我输入文本框 1,3 那么 checkbox1 和 checkbox3 将被禁用而不被选中!
我在下面提供的编码正在工作,但是...它根据文本框中的文本检查 cjeckoxes,即 (1,3),然后将检查 checkbox1 和 checkbox3 ..
..但我希望当我在文本框中输入 1,3 时,checkbox1 和 checkbox3 将被禁用并保持未选中状态........................
任何人都可以更新我的代码来执行上述操作吗?
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim separator As Char = ","
Dim allIIDs As New List(Of Int32)
If TextBox1.Text.Length <> 0 Then
For Each strNum As String In TextBox1.Text.Split(separator)<br>
Dim num As Int32
If Int32.TryParse(strNum, num) Then
allIIDs.Add(num)
End If
Next
End If
allIIDs.Sort()
For Each control As Control In Panel1.Controls
If TypeOf control Is CheckBox Then
Dim chk As CheckBox = DirectCast(control, CheckBox)
chk.Enabled = False = allIIDs.BinarySearch(Int32.Parse(chk.Text)) > -1
End If
Next
End Sub
我假设您希望禁用那些在文本框中列出的以逗号分隔的复选框and启用其他复选框。 (改进了一点你的代码,因为起初 https://stackoverflow.com/questions/4173949/i-have-4-checkboxes-and-1-textbox-in-webform-if-i-type-in-textbox-1-2-then-checkb/4174390#4174390它来自我)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim separator As Char = ","c
Dim allIIDs As New List(Of String)
If TextBox1.Text.Length <> 0 Then
For Each strNum As String In TextBox1.Text.Split(separator)
Dim num As Int32
If Int32.TryParse(strNum, num) Then
allIIDs.Add(strNum)
End If
Next
End If
allIIDs.Sort()
For Each control As Control In Panel1.Controls
If TypeOf control Is CheckBox Then
Dim chk As CheckBox = DirectCast(control, CheckBox)
chk.Enabled = allIIDs.BinarySearch(chk.Text) < 0
End If
Next
End Sub
记得设置一下AutoPostBack="false"
到 TextBox1,否则您需要 2 次回发才能看到复选框的禁用状态。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)