如何根据文本框的文本检查复选框? [英] How to checked checkboxes according to textbox text ?

查看:90
本文介绍了如何根据文本框的文本检查复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络表单上有4个复选框和1个文本框.如果我在文本框中输入1,2,则将选中checkbox1和checkbox2.为此的代码如下. 但是我想当我输入1,2时,应该禁用并且未选中checkbox1和checkbox2.

有人可以更新此代码吗?

I have 4 checkboxes and 1 textbox on a web-form. If I type 1,2 in the textbox, then checkbox1 and checkbox2 will be checked. The code for this is as below. But I want when I type 1,2 then checkbox1 and checkbox2 should be disabled and unchecked.

Can anybody update this code?

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim separator As Char = ","c
        Dim allIIDs As New List(Of Int32)
        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(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.Checked = allIIDs.BinarySearch(Int32.Parse(chk.Text)) > -1
            End If
        Next
    End Sub



添加了代码块以提高可读性-OriginalGriff [/edit]



[edit]Code block added to improve legibility - OriginalGriff[/edit]

推荐答案

当我在文本框中输入1,2时,上述代码将检查checkbox1和checkbox2. ...


但是我想当我在文本框中输入1,2时,checkbox1和checkbox2也将被取消选中并被禁用... !!


任何人都可以编辑上面的代码来执行此操作吗?
THe above code will check the checkbox1 and checkbox2 when i type 1,2 in textbox....


But i want when i type1,2 in textbox then checkbox1 and checkbox2 will be unchecked and disabled also ... !!


can any body edit my code above to do that ?


这篇关于如何根据文本框的文本检查复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆