如果我输入文本框1,3则复选框1和复选框3将被禁用未选中!!
我在下面提供的编码是可行的,但是......根据文本框中的文本(即1,3),然后复选checkbox1和checkbox3将检查cjeckoxes ..
..但我希望当我在文本框中键入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
答案 0 :(得分:0)
我假设您希望禁用那些在TextBox 和中列出的逗号分隔的复选框,并启用其他复选框。 (改进了一点你的代码,因为originally它来自我)
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个Postback才能看到复选框的禁用状态。