ASP.NET、VB:检查选择了 CheckBoxList 中的哪些项目
我知道这是一个非常基本的问题,但我找不到如何在 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以循环遍历 CheckBoxList 中的复选框,检查每个复选框以查看是否已选中。尝试这样的操作:
上面的代码将被放置在 CheckBoxList 的
SelectedIndexChanged
事件处理程序中。You can loop through the checkboxes in a CheckBoxList, checking each to see if it is checked. Try something like this:
The above code would be placed in the CheckBoxList's
SelectedIndexChanged
event handler.假设您的 aspx 看起来与此类似:
您可以使用 ListItem's-
Selected
属性来检查是否应启用您的文本框:Assuming that your aspx look similar to this:
you can use the ListItem's-
Selected
property to check if your Textbox should be enabled:我不会这样做,效率很低。您只是为了启用或禁用文本框而访问服务器,您应该使用 javascript。下面的代码会更好
I wouldn't do it this way, it's very inefficient. You are hitting the server just to enable or disable a text box, you should use javascript. The code below would be better
将它们放入字符串中的函数
Funtion to get them in a string