1。界面显示
CheckBoxList1.DataSource = ds.Tables[0];//所有选项存到数据库
CheckBoxList1.DataTextField = "name";
CheckBoxList1.DataValueField = "id";
CheckBoxList1.DataBind();

2。保存到数据库
string name = "";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
name+= CheckBoxList1.Items[i].Value + "|";
}
}
if (name!= "")
{
name = name.Substring(0, otherdept.Length - 1);
}
然后把name保存到你的表的一列里。

3。从数据库读取
string name=从数据库读取保存的那列。
string[] names;
names= name.Split('|');
for (int i = 0; i < names.Length; i++)
{
CheckBoxList1.Items.FindByValue(names[i]).Selected = true;
}

相关文章:

  • 2021-05-18
  • 2022-12-23
  • 2021-11-10
  • 2021-11-05
  • 2021-08-28
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2018-09-18
  • 2021-12-14
  • 2021-07-03
  • 2021-10-25
  • 2021-09-22
相关资源
相似解决方案