CheckBoxList总结

添加控件:
<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;
                 }
             }
         }

posted @ 2013-05-20 23:19  Trilyn  阅读(115)  评论(0)    收藏  举报