<asp:CheckBoxList ID="cbltype" runat="server" RepeatLayout="Flow" RepeatColumns="12">
2.绑定
DataTable dt = StaffBusiness.GetMSStaffList(CommonBusiness.GetLoginInfo(this.LoadStaffid, 1), int.Parse(str));
ddlMStaffID.DataSource = dt;
ddlMStaffID.DataTextField = "staffname";
ddlMStaffID.DataValueField = "staffid";
ddlMStaffID.DataBind();
3.赋值
if (cbltype.Items.Count > 0)
{
for (int i = 0; i < cbltype.Items.Count; i++)
{
cbltype.Items[i].Selected = false;
}
DataTable dt = StaffBusiness.GetStafftypeList(id);
for (int i = 0; i < dt.Rows.Count; i++)
{
ListItem li = cbltype.Items.FindByValue(dt.Rows[i]["typeid"].ToString());
if (li != null)
{
li.Selected = true;
}
}
}
4.取值
string strcbltype = "";
for (int i = 0; i < cbltype.Items.Count; i++)
{
if (cbltype.Items[i].Selected)
{
strcbltype += cbltype.Items[i].Value + ",";
}
}