<asp:CheckBoxList ID="ddMaterial" runat="server">
</asp:CheckBoxList>
为checklistbox绑定list
TbSortMaterialList designerList = TbSortMaterial.GetTbSortMaterialListNoPage();
for (int i = 0; i < designerList.Count; i++)
{
string text = designerList[i].MaterialName;
string value = (designerList[i].MaterialId).ToString();
ddMaterial.Items.Add(new ListItem(text, value));
}
从数据库查出选中显示时,在数据库里保存形式是以逗号隔开的value
string[] arr = tgobj.ProductMaterial.Split(',');
for (int i = 0; i < arr.Length-1; i++)
{
for (int J = 0; J < ddMaterial.Items.Count; J++)
{
if (ddMaterial.Items[J].Value == arr[i].ToString())
{
ddMaterial.Items[J].Selected = true;
}
}
}
修改提交保存时
string material ="";
for (int i = 0; i < ddMaterial.Items.Count; i++)
{
if (ddMaterial.Items[i].Selected)
{
material += ddMaterial.Items[i].Value + ",";
}
}