0

How can i set all selected items from an Checkboxlist into a list? I tried this code but when i run it all checkbox items where added? I only want the selected items

List<string> WeeklyDays = (from l in CheckBoxListWeeklyDays.Items.Cast<ListItem>() select l.Value).ToList();
user3702149
  • 17
  • 1
  • 6

1 Answers1

0
  1. Your snippet is C#/ASP.NET not vbscript/classic-asp
  2. In your query add a WHERE statement to look at the "Selected" attribute of each ListItem, similar to:

List WeeklyDays = (from l in CheckBoxListWeeklyDays.Items.Cast() where l.Selected select l.Value).ToList();

Taken from: How to get values of selected items in CheckBoxList with foreach in ASP.NET C#?

Community
  • 1
  • 1
Gary Richter
  • 526
  • 4
  • 16