写写程序,一种成就的感觉

写写程序,一种成就的感觉

导航

CheckBoxList 选中值及修改的默认值代码

Posted on 2010-04-20 17:29  hateyoucode  阅读(875)  评论(0)    收藏  举报

取值代码

 

代码
for (int i = 0; i < CheckBoxList1.Items.Count; i++) {
if (CheckBoxList1.Items[i].Selected == true) {
if (checkid != string.Empty)
checkid
+= "," + CheckBoxList1.Items[i].Value; else
checkid
+= CheckBoxList1.Items[i].Value;
}
}

 

 


 

 

 

 

修改的时候默认值的代码

 

代码
if (Info.CourseId != string.Empty)
{
string[] str = Info.CourseId.Split(new char[] { ',' });
foreach (string strinfo in str)
{
ListItem NewItem
= (ListItem)CheckBoxList1.Items.FindByValue(strinfo);
if (NewItem != null)
NewItem.Selected
= true;
}
}