CheckBoxList

StringBuilder sbEquipment = new StringBuilder();
foreach (ListItem li in chklEquipment.Items)
{
    if (li.Selected)
    {
        sbEquipment.AppendFormat("{0}|", li.Text);
    }
}

if (sbEquipment.Length > 1)
{
    sbEquipment.Remove(sbEquipment.Length - 1, 1);
}

//string strEquipment = String.Empty;
string[] arrEquipment = strEquipment.Split(new char[] { '|' });

foreach (ListItem li in chklEquipment.Items)
{
    foreach (string str in arrEquipment)
    {
        if (li.Text.Equals(str))
        {
            li.Selected = true;
            break;
        }
    }
}

posted @ 2010-08-01 16:01  libingql  阅读(176)  评论(0编辑  收藏  举报