CheckBoxList1獲取選中項和綁定選中項


頁面添加一個CheckBoxList1,后台進行數據綁定,關鍵代碼如下:

 1 DataSet ds = gl.GetList("(isdelete = 0 or isdelete is null) AND (iscost=0 or iscost is null)");
 2             CheckBoxList1.DataSource = ds;
 3             CheckBoxList1.DataTextField = "lcmc";
 4             CheckBoxList1.DataValueField = "id";
 5             CheckBoxList1.DataBind();
 6             foreach (ListItem lst in this.CheckBoxList1.Items)
 7             {
 8                 YHGLDS model = YH.GetModel(1);
 9 
10                 string[] arr = model.xzcf_qx.ToString().Trim().Split(',');
11                 for (int i = 0; i < arr.Length; i++)
12                 {
13                     if (arr[i].ToString().Equals(lst.Value))
14                         lst.Selected = true;
15                 }
16             }

綁定之后,保存時進行選中的保存 ,關鍵代碼如下:

 1  YHGLDS model = YH.GetModel(1);
 2             string qxsz = "";
 3             foreach (ListItem lst in this.CheckBoxList1.Items)
 4             {
 5 
 6                     if (lst.Selected == true)
 7                     {
 8                         qxsz += lst.Value+",";
 9                         
10                     }
11                         
12                 
13             }
14             model.xzcf_qx = qxsz.Trim(',');

 接下來便是可以直接顯示,進行使用了;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM