如何在Asp.net中的CheckBoxList中获取所选项目

Ari*_*ian 6 c# linq asp.net

我的页面中有一个CheckBoxList.有没有办法使用linq获取所有选定的项目值?

在CheckBoxList中获取所选项值的最佳方法是什么?

A. *_*per 19

您可以通过获取复选框列表中的项目并将它们转换为ListItems并从该集合中获取所选内容,如下所示:

var selectedItems = yourCheckboxList.Items.Cast<ListItem>().Where(x => x.Selected);
Run Code Online (Sandbox Code Playgroud)