I am creating a CheckBoxList in a class file and am using an HTMLTextWriter to render the control.
I\'m using the following code to store the selected values in a s
An elegant way to implement this would be to make an extension method, like this:
public static class Extensions
{
public static List GetSelectedItems(this CheckBoxList cbl)
{
var result = new List();
foreach (ListItem item in cbl.Items)
if (item.Selected)
result.Add(item.Value);
return result;
}
}
I can then use something like this to compose a string will all values separated by ';':
string.Join(";", cbl.GetSelectedItems());