CheckBoxList获取设置值

简单写下 CheckBoxList获取设置值的方法:

获取值:

  
  
  
  
  1. string strSelectValue = ""
  2. foreach (ListItem item in 控件ID.Items) 
  3.     if (item.Selected) 
  4.     { 
  5.         strSelectValue += item.Text + ","
  6.     } 

 

设置值:

  
  
  
  
  1. foreach (ListItem item in 控件ID.Items) 
  2.       { 
  3.          //strSelectValue 为要设置选中的项字符串的集合 
  4.           string[] strstrSplit = strSelectValue.Split(new char[1]{','}, StringSplitOptions.RemoveEmptyEntries); 
  5.           foreach (string str in strSplit) 
  6.           { 
  7.               if (str == item.Text) 
  8.               { 
  9.                   item.Selected = true
  10.               } 
  11.           } 
  12.       }  

 

 

你可能感兴趣的:(职场,checkboxlist,休闲,获取设置)