CheckBoxList 初始化、赋值、选中

        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="checkList"></param>
        private void InitChecked(CheckBoxList checkList)
        {
            for (int i = 0; i < checkList.Items.Count; i++)
            {
                checkList.Items[i].Selected = false;
            }
        }
        /// <summary>
        /// 控件赋值
        /// </summary>
        /// <param name="checkList"></param>
        /// <param name="selval"></param>
        private void SetChecked(CheckBoxList checkList, string selval)
        {
            for (int i = 0; i < selval.Length; i++)
            {
                for (int j = 0; j < checkList.Items.Count; j++)             
                {
                    if (selval.Substring(i,1)==checkList.Items[j].Value)
                    {
                        checkList.Items[j].Selected = true; 
                    }
                }
            }
        }

        /// <summary>
        /// 获取控件选中值
        /// </summary>
        /// <param name="checkList"></param>
        /// <returns></returns>
        private string GetChecked(CheckBoxList checkList)
        {
            string strSelected = ""; 
             for (int i = 0; i < checkList.Items.Count; i++)//读取CheckBoxList 选中的值,保存起来             
             { 
                 if (checkList.Items[i].Selected) 
                 { 
                     strSelected += checkList.Items[i].Value; 
                 } 
             } 
            return strSelected;
        }

 

posted @ 2014-08-14 15:48  linyongqin  阅读(1693)  评论(0编辑  收藏  举报