Showing posts with label Check Box. Show all posts
Showing posts with label Check Box. Show all posts

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(',');
}

Get Check Box Selected Values

public static string GetSelectedValues(CheckBoxList chkBoxList)
{
string selectedValue = string.Empty;

foreach (ListItem listItem in chkBoxList.Items)
{
if (listItem.Selected)
selectedValue += listItem.Value + ",";
}

return selectedValue.Trim(',');
}