为什么不用<asp:checkboxlist控件

解决方案 »

  1.   

    是啊!可以用checkboxlist:
    1、选项值保存到数据库
       string SelectItem = "";//声明一个变量来接受选项
       for (int i = 0; i < CheckBoxListID.Items.Count; i++)
       {//用for循环将所有选项用","隔开连接起来
            if (CheckBoxListID.Items[i].Selected)
            {
                SelectItem = SelectItem + CheckBoxListID.Items[i].Value + ",";//选项后加","隔开
            }
       }
       ht.Add("字段名",SelectItem.ToString());2、选项值由数据库绑定到CheckBoxList
       string SelectItem = dr["字段名"].ToString();
       string[] arrStr = SelectItem.Split(',');//字段是以","隔开
       foreach (string str in arrStr)
       {
           for (int i = 0; i <CheckBoxListID.Items.Count; i++)
           {
              if (this.CheckBoxListID.Items[i].Value == str)
              {
                 this.CheckBoxListID.Items[i].Selected = true;
              }
           }
       }