gpt4 book ai didi

ASP.NET, VB : checking which items of a CheckBoxList are selected

转载 作者:行者123 更新时间:2023-12-01 00:40:46 27 4
gpt4 key购买 nike

我知道这是一个非常基本的问题,但我找不到如何在 VB 中执行此操作...我有一个 CheckBoxList,其中一个选项包括一个用于填写您自己的值的文本框。所以我需要在选中它的复选框(CheckBoxList 中的 ListItem)时启用该文本​​框。这是后面的代码,我不确定在我的 If 语句中放入什么来测试是否检查了某个 ListItem。

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

最佳答案

您可以遍历 CheckBoxList 中的复选框,检查每个复选框以查看是否已选中。试试这样的:

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

以上代码将被放置在 CheckBoxList 的 SelectedIndexChanged 事件处理程序中。

关于ASP.NET, VB : checking which items of a CheckBoxList are selected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4629571/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com