获取复选框的值在CheckBoxList控件

编程入门 行业动态 更新时间:2024-10-28 02:21:37
本文介绍了获取复选框的值在CheckBoxList控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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功能的背景(这是错误反正),然后又在对于每个 - 还不如干脆做一个...

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控件

本文发布于:2023-11-06 15:59:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   复选框   CheckBoxList

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!