获取复选框的值在CheckBoxList控件 [英] getting the values of checkboxes in a checkboxlist control
问题描述
我有一个asp:我的网页上的CheckBoxList,我需要得到选中的复选框的值
I have an asp:CheckboxList on my page and I need to get the values of the checked checkboxes.
所以,我有那么遍历,但是我发现没有办法来检索与个人复选框相关的值LINQ查询。
So I have a linq query that I then loop through, but I've discovered that there is no way to retrieve the values associated with the individual checkboxes.
下面是我的code:
Dim checkboxValues = cblmyCheckboxes.Controls.OfType(Of CheckBox)().Where(Function(c) c.Checked)
For Each c As CheckBox In checkboxValues
Response.Write(c.Value)
Next
我怎样才能获得价值?
How can I get the values?
感谢
推荐答案
您复选框列表中包含列表项
,而不是复选框。所以cblmyCheckboxes.Items是 ListItemCollection
Your Checkbox List contains ListItem
and not checkbox. So cblmyCheckboxes.Items is a ListItemCollection
真的,更快,更简单的方法是:
Really, a quicker and easier way would be:
For Each li as ListItem in cblmyCheckboxes.Items
If (li.Selected) Then
Dim XX = li.Value
'' Do something with Value
End If
Next
使用LINQ你有效地通过复选框循环列出的项目(在你的LINQ功能的背景(这是错误反正),然后又在对于每个$ C $再次循环C> - 还不如干脆做一个...
By using LINQ you're effectively looping through the checkbox lists items (in the background of your LINQ function (which is wrong anyway) and then also looping again in your For Each
- might as well just do the one...
这篇关于获取复选框的值在CheckBoxList控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!