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;
}
}
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;
}
}