Checking if CheckBoxList has any selected values

Viredae picture Viredae · Aug 15, 2010 · Viewed 15.4k times · Source

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.

Answer

Eyeball picture Eyeball · Aug 1, 2011

The Linq extension method is neat, but you can also just check the SelectedIndex:

bool isAnySelected = CheckBoxList1.SelectedIndex != -1;

If nothing is checked, the SelectedIndex is -1.