Showing posts with label count selected items of checkboxlist. Show all posts
Showing posts with label count selected items of checkboxlist. Show all posts

Saturday, September 24, 2011

count selected items of checkboxlist and also separate it with comma

A simple way to count only selected items of checkboxlist

 var totalcount = CheckBoxList1.Items.Cast<ListItem>().Where(item => item.Selected).Count();


now If you want separte it with comma then



 foreach (ListItem selectedItem in CheckBoxList1.Items)
        {
            if (selectedItem.Selected)
            {


                if (string.IsNullOrEmpty(selectedExch))


                    selectedExch = selectedItem.Value;


                else


                    selectedExch = selectedExch + "," + selectedItem.Value;


            }


        }