How to loop through a checkboxlist and to find what's checked and not checked?

后端 未结 6 2165
-上瘾入骨i
-上瘾入骨i 2020-12-18 18:47

I\'m trying to loop through items of a checkbox list. If it\'s checked, I want to set a value. If not, I want to set another value. I was using the below, but it only gives

6条回答
  •  清酒与你
    2020-12-18 19:31

    This will give a list of selected

    List items =  checkboxlist.Items.Cast().Where(n => n.Selected).ToList();
    

    This will give a list of the selected boxes' values (change Value for Text if that is wanted):

    var values =  checkboxlist.Items.Cast().Where(n => n.Selected).Select(n => n.Value ).ToList()
    

提交回复
热议问题