添加控件:
<asp:CheckBoxList ID="chkDictItem" runat="server" RepeatDirection="Horizontal" RepeatLayout="Table" RepeatColumns="3" >
</asp:CheckBoxList>
初始化:
chkDictItem.DataSource = dtSource;
chkDictItem.DataValueField = "No";
chkDictItem.DataTextField = "Description";
chkDictItem.DataBind();
取值:
string dictValue = "";
for (int i = 0; i < this.chkDictItem.Items.Count; i++)
{
if (this.chkDictItem.Items[i].Selected == true)
{
dictValue += this.chkDictItem.Items[i].Value + "," + this.chkDictItem.Items[i].Text + "|";
}
}
设选定值:
string[] arr = dictValue.Split(',');
foreach (string str in arr)
{
for (int i = 0; i < this.chkDictItem.Items.Count; i++)
{
if (this.chkDictItem.Items[i].Value == str)
{
this.chkDictItem.Items[i].Selected = true;
}
}
}