Search code examples
asp.netcheckboxlist

Checking if CheckBoxList has any selected values


I would like to know the fastest/easiest way to check if a CheckBoxList control has any checked items or not, I'm talking about an entire checkbox list as a whole, not a single checkbox.


Solution

  • This one should help:

    bool isAnySelected = checkBoxList.Items.Any(i => i.Selected);
    

    .Any is a Linq extension method, so you will need the System.Linq or .System.Linq.Extensions reference (can't remember which) in your code-behind.