checkboxlist控件的使用  

  /// <summary>
    /// 获取CheckBoxList复选框组中被选中的2.并生成0和1组成的字符串
    /// </summary>
    /// <param name="cblName">CheckBoxList的实例</param>
    /// <returns>返回一个0和1组成的字符串</returns>
    protected string getCheckBoxList(CheckBoxList cblName)
    {
        string strResult;
        foreach (ListItem li in cblName.Items)
        {
            if (li.Selected == true)
            {
                strResult += 1;
            }
            else
            {
                strResult += 0;
            }
        }
    }

    /// <summary>
    /// 根据0和1组成的字符串还原成checkboxlist选项值
    /// </summary>
    /// <param name="strCBL">数据库中的字符串</param>
    /// <param name="cblName">checkboxlist控件的实例</param>
    protected void setCheckBoxList(string strCBL, CheckBoxList cblName)
    {
        char[] charCBL = strCBL.ToCharArray();        //把字符串转换为字符数组
        for (int i = 0; i < cblName.Items.Count; i++)  //遍历复选框组
        {
            if(charCBL[i].Equals('1'))  //索引相同,如果字符的值为一,那么复选框选中
            {
                cblName.Items[i].Selected=true; //选中复选框
            }
        }
    }
原文地址:https://www.cnblogs.com/ly5201314/p/1385523.html