I have a checkedlistBox cblHobbies
StringBuilder hobbies = new StringBuilder(string.Empty);
foreach (ListItem li in cblHobbies.Items) {
if (li.Selected) {
hobbies.Append(li).Append(", ");
}
}
string hobby = hobbies.ToString().TrimEnd(' ').TrimEnd(',');
I am storing hobby in SQL Server database as Varchar(MAX).
When the user edit his profile i want all the hobbies get selected already.
My Question is how to select checklistbox items from a comma separated list efficiently? (in respect of number of iterations)
string hobby=String.Join(", ", cblHobbies.Items.Cast<ListItem>().Where(i=>i.Selected));