ASP.NET,VB:检查这是选择的CheckBoxList的项目 [英] ASP.NET, VB: checking which items of a CheckBoxList are selected
问题描述
我知道这是一个非常基本的问题,但我怎么也找不到在VB中做到这一点...我有一个的CheckBoxList,其中的一个选项包括一个文本框填你自己的价值。所以,我需要有一个文本框会启用时,其复选框(在一个的CheckBoxList列表项)进行检查。这是code后面,我不知道要放什么东西在我的if语句来测试,如果某些列表项被选中。
保护小组CheckBoxList1_SelectedIndexChanged(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手CheckBoxList1.SelectedIndexChanged
如果___然后
txtelect.Enabled = TRUE
其他
txtelect.Enabled =假
万一
结束小组
您可以通过在的CheckBoxList复选框,检查每个看它是否被选中循环。尝试是这样的:
对于每个李鸿章为列表项在CheckBoxList1.Items
如果li.Value =ValueOfInterest然后
好吧,这是我们关心的,以确定是否文本框应该启用将CheckBox ......是选中复选框?
如果li.Selected然后
'是的!启用文本框
MyTextBox.Enabled = TRUE
其他
它没有被选中,禁用文本框
MyTextBox.Enabled =假
万一
万一
下一个
以上code将被放置在的CheckBoxList的的SelectedIndexChanged
事件处理程序。
I know this is an extremely basic question, but I couldn't find how to do this in VB... I have a CheckBoxList where one of the options includes a textbox to fill in your own value. So I need to have that textbox become enabled when its checkbox (a ListItem in the CheckBoxList) is checked. This is the code behind, I'm not sure what to put in my If statement to test if that certain ListItem is checked.
Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
If ___ Then
txtelect.Enabled = True
Else
txtelect.Enabled = False
End If
End Sub
You can loop through the checkboxes in a CheckBoxList, checking each to see if it is checked. Try something like this:
For Each li As ListItem In CheckBoxList1.Items
If li.Value = "ValueOfInterest" Then
'Ok, this is the CheckBox we care about to determine if the TextBox should be enabled... is the CheckBox checked?
If li.Selected Then
'Yes, it is! Enable TextBox
MyTextBox.Enabled = True
Else
'It is not checked, disable TextBox
MyTextBox.Enabled = False
End If
End If
Next
The above code would be placed in the CheckBoxList's SelectedIndexChanged
event handler.
这篇关于ASP.NET,VB:检查这是选择的CheckBoxList的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!