Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如果我输入文本框1,3,则checkbox1和checkbox3将被禁用未选中!_Asp.net_Vb.net - Fatal编程技术网

Asp.net 如果我输入文本框1,3,则checkbox1和checkbox3将被禁用未选中!

Asp.net 如果我输入文本框1,3,则checkbox1和checkbox3将被禁用未选中!,asp.net,vb.net,Asp.net,Vb.net,如果我输入文本框1,3,则checkbox1和checkbox3将被禁用未选中 我在下面提供的编码正在工作,但是,…它根据文本框中的文本检查CJECKOX,即(1,3),然后选中复选框1和复选框3 。。但我想当我在文本框中键入1,3时,复选框1和复选框3将被禁用并保持未选中状态 任何机构可以更新我的代码来执行上述操作吗 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

如果我输入文本框1,3,则checkbox1和checkbox3将被禁用未选中

我在下面提供的编码正在工作,但是,…它根据文本框中的文本检查CJECKOX,即(1,3),然后选中复选框1和复选框3

。。但我想当我在文本框中键入1,3时,复选框1和复选框3将被禁用并保持未选中状态

任何机构可以更新我的代码来执行上述操作吗

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
Protected Sub Button1\u Click(ByVal sender作为对象,ByVal e作为System.EventArgs)处理按钮1。单击
将分隔符变暗为Char=“,”
Dim Allids作为新列表(Int32)
如果TextBox1.Text.Length为0,则
对于TextBox1.Text.Split(分隔符)中作为字符串的每个字符串
Dim num作为Int32 如果Int32.TryParse(strNum,num),那么 allids.Add(num) 如果结束 下一个 如果结束 allids.Sort() 对于每个控件作为Panel1.控件中的控件 如果控件类型为复选框,则 Dim chk As CheckBox=DirectCast(控件,复选框) chk.Enabled=False=allids.BinarySearch(Int32.Parse(chk.Text))>-1 如果结束 下一个 端接头
我假设您希望禁用文本框中以逗号分隔的复选框,并启用其他复选框。(你的代码改进了一点,因为它来自我)

受保护的子按钮1\u单击(ByVal sender作为对象,ByVal e作为事件参数)处理按钮1。单击
尺寸分隔符为Char=“,”c
将AllID变暗为新列表(字符串)
如果TextBox1.Text.Length为0,则
对于TextBox1.Text.Split(分隔符)中的字符串形式的每个字符串
Dim num作为Int32
如果Int32.TryParse(strNum,num),那么
蒜状体添加(strNum)
如果结束
下一个
如果结束
allids.Sort()
对于每个控件作为Panel1.控件中的控件
如果控件类型为复选框,则
Dim chk As CheckBox=DirectCast(控件,复选框)
chk.Enabled=allids.BinarySearch(chk.Text)<0
如果结束
下一个
端接头

请记住将
AutoPostBack=“false”
设置为TextBox1,否则您需要两次回发才能查看复选框的禁用状态。

我不确定您到底想要什么。Hey tim的确切副本,但是。。。当我在文本框中键入…1,2时,checkbox1和checkbox2将被禁用,然后当我在文本框中键入3,4时,1,2将被启用,checkbox3和checkbox4将被禁用。是的,这不正是你想要的吗?
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