当前位置:编程学习 > 网站相关 >>

CheckBoxList获取设置值

 

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

获取值:

string strSelectValue = "";

foreach (ListItem item in 控件ID.Items)

{

    if (item.Selected)

    {

        strSelectValue += item.Text + ",";

    }

}

 

设置值:

 foreach (ListItem item in 控件ID.Items)

      {

         //strSelectValue 为要设置选中的项字符串的集合

          string[] strstrSplit = strSelectValue.Split(new char[1]{','}, StringSplitOptions.RemoveEmptyEntries);

          foreach (string str in strSplit)

          {

              if (str == item.Text)

              {

                  item.Selected = true;

              }

          }

      } 

 

 

本文出自 “小白龙” 博客

补充:综合编程 , 安全编程 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,