Tuesday, September 22, 2009

Set CheckBox Selected Values

public static string SetSelectedValues(CheckBoxList chkBoxList, string selectedValues)
{
string selectedValue = string.Empty;

foreach (string selValue in selectedValues.Split(','))
{
ListItem listItem = chkBoxList.Items.FindByValue(selValue);
if (listItem != null)
{
listItem.Selected = true;
selectedValue += listItem.Value + ",";
}
}

return selectedValue.Trim(',');
}

No comments: