asp.netc#-2.0checkboxlist

any easy way to check if no items has been selected in a checkboxlist control?


I know I can loop through a checkboxlist.Items and see if none of them is selected, but is there a better way to find out if no items have been selected, in the code behind?


Solution

  • You have to check the SelectedIndex. If it equals -1, its means nothing is selected.

     CheckBoxList list = new CheckBoxList();
     if (list.SelectedIndex == -1)
     {
          //Nothing is selected
     }