As a simplified example, I have a CheckBoxList that contains 3 Items as follows:
The result is written to single column (Colors) in my database and the some of the possible values could be "Red" or "Red,Green" or "Green,Blue" or "Red,Green,Blue"....and so on.
When I read the value from the database into a string "SelectedColors", how can I then use the value of "SelectedColors" to set the corresponding ListItems as Checked?
Thanks
Gary
Amit ChoudharyPosted Jul 7, 2011, 5:35 AM
Use below code for item selection based on values:
string selectedColors="Red, Green";
foreach (ListItem item in cblColors.Items)
{
if (selectedColors.Contains(item.Text))
{
item.Selected = true;
}
}
Please mark it as answer if it helped you.
Thanks.
Monika NarulaPosted Jul 28, 2018, 1:50 AM