开发者

if i type in textbox 1,3 then checkbox1 and checkbox3 will be disabled not checked !

开发者 https://www.devze.com 2023-01-24 20:17 出处:网络
if i type in textbox 1,3 then checkbox1 and checkbox3 will be disabled not checked !! The coding i provide below is working but ,...it chekec the cjeckoxes according to the text in textbox i.e (1,3)

if i type in textbox 1,3 then checkbox1 and checkbox3 will be disabled not checked !!

The coding i provide below is working but ,...it chekec the cjeckoxes according to the text in textbox i.e (1,3) then checkbox1 and checkbox3 will be checked ..

.. but i want when i type 1,3 in textbox then checkbox1 and checkbox3 will be disabled and remain unchecked .........

can any body update my this code to perform above operation ?

Protected Sub Button1_C开发者_运维问答lick(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


I assume that you want those checkboxes disabled that are comma separated listed in the TextBox and the other checkboxes enabled. (improved a little bit your code, because originally it came from me)

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

Remember to set AutoPostBack="false" to TextBox1, otherwise you need 2 Postbacks to see the disabled state of the checkboxes.

0

精彩评论

暂无评论...
验证码 换一张
取 消