for(int i=0;i<=this.CHRight.Items.Count-1;i++)
{
if(this.CHRight.Items[i].Selected)
{
role.Right+=this.CHRight.SelectedItem.Text.ToString()+","; }
}
好像不行吧!

解决方案 »

  1.   

    你的是有问题,可以这样写
              #region CheckBoxList
            /// <summary>
            /// 获取CheckBoxList选中的值
            /// </summary>
            /// <param name="cbl"></param>
            /// <returns></returns>
            public static string GetCheckBoxList(CheckBoxList cbl)
            {
                string _retval = string.Empty;            foreach (ListItem item in cbl.Items)
                {
                    if (item.Selected)
                        _retval += item.Value + ",";
                }            _retval = _retval.Remove(_retval.LastIndexOf(","), 1);//删除最后一个","            return _retval;
            }
            /// <summary>
            /// 重置CheckBoxList
            /// </summary>
            /// <param name="cbl"></param>
            public static void ResetCheckBoxList(CheckBoxList cbl)
            {
                foreach (ListItem item in cbl.Items)
                {
                    item.Selected = false;
                }
            }        /// <summary>
            /// 给CheckBoxList赋初始值
            /// </summary>
            /// <param name="cbl"></param>
            /// <param name="strArr"></param>
            public static void SetCheckBoxList(CheckBoxList cbl,string[] strArr)
            {
                //赋值之前先把原有的值给清除
                ResetCheckBoxList(cbl);            foreach (string val in strArr)
                {
                    if (val != "")
                    {
                        foreach (ListItem item in cbl.Items)
                        {
                            if (item.Value == val)
                                item.Selected = true;
                        }
                    }
                }
            }
            #endregion
      

  2.   

    string ss="";
    for(int   i=0;i <=this.CHRight.Items.Count-1;i++) 

    if(this.CHRight.Items[i].Selected) 
    { ss+=this.CHRight.Items[i].value+"|";