gpt4 book ai didi

c# - 在 asp.net 中检查是否所有复选框都被选中 == false

转载 作者:太空宇宙 更新时间:2023-11-03 22:17:20 25 4
gpt4 key购买 nike

foreach(Listitem item in CheckboxList1.Items)
{
if(item.Selected == true)
{
return true;
}
}
return false;

有没有更好的方法来检查所有选中的复选框是否为 false?

最佳答案

您可以非常轻松地使用 LINQ:

return CheckboxList1.Items
.Cast<ListItem>()
.Any(item => item.Selected);

(需要调用 Cast,因为 ListItemCollection 没有实现 IEnumerable<T>,只有非通用集合接口(interface)。)

关于c# - 在 asp.net 中检查是否所有复选框都被选中 == false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4591479/

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