当我键入1,2,然后checkbox1和checkbox2将禁用和未选中 [英] when i type 1,2 then checkbox1 and checkbox2 will disabled and unchecked
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/4173949/i-have-4-checkboxes-and-1-textbox-in-webform-if-i-type-in-textbox-1-2-then-checkb\">I有4个复选框,并在Web窗体1的文本框,如果我在文本框1,2然后checkbox1&放类型; 2将被检查!
块引用>我有4个选择框和文本框1一个网络形式。如果我在文本框中键入1,2,那么
checkbox1
和checkbox2
将被检查。在code因为这是如下。但我想的是,当我输入1,2则checkbox1
和checkbox2
应禁用和选中。任何人都可以更新此code?
保护小组的button1_Click(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手Button1.Click
昏暗的分隔符为char =,C
昏暗allIIDs作为新的列表(中的Int32)
如果TextBox1.Text.Length&LT;&GT; 0,则
对于每个strNum作为字符串在TextBox1.Text.Split(分隔符)
昏暗的NUM作为的Int32
如果Int32.TryParse(strNum,NUM)则
allIIDs.Add(NUM)
万一
下一个
万一
allIIDs.Sort()
对于每个控制作为控制在Panel1.Controls
如果TypeOf运算控制是复选框然后
DIM清洁香港作为复选框= DirectCast(控制,复选框)
chk.Checked = allIIDs.BinarySearch(Int32.Parse(chk.Text))GT; -1
万一
下一个
结束小组
解决方案你有没有尝试设置启用以虚假和检查,以假的?
chk.Checked = chk.Enabled = allIIDs.BinarySearch(Int32.Parse(chk.Text))&LT; = -1
Possible Duplicate:
I have 4 checkboxes and 1 textbox in webform if i type in textbox 1,2 then checkbox1 & 2 will be checked !I have 4 checkboxes and 1 textbox on a web-form. If I type 1,2 in the textbox, then
checkbox1
andcheckbox2
will be checked. The code for this is as below. But what I want is that when I type 1,2 thencheckbox1
andcheckbox2
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
解决方案Have you tried setting Enabled to false and Checked to false?
chk.Checked = chk.Enabled = allIIDs.BinarySearch(Int32.Parse(chk.Text)) <= -1
这篇关于当我键入1,2,然后checkbox1和checkbox2将禁用和未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!