• 取得checkboxlist选中项的值;初始化CheckBoxList中哪些是选中了的


    取得checkboxlist选中项的值
    /// <summary>
           
    /// 取得checkboxlist选中项的值
           
    /// </summary>
           
    /// <returns>选中项的值</returns>
            private string BindCheckBoxList()
            {
               
    string str = string.Empty;
               
    for (int i = 0; i < this.cbKeyWord.Items.Count; i++)
                {
                   
    if (this.cbKeyWord.Items[i].Selected)
                    {
                        str
    += cbKeyWord.Items[i].Value + ",";
                    }
                }
               
    return !str.Equals(string.Empty) ? str.Remove(str.Length - 1, 1) : "";
            }
    初始化CheckBoxList中哪些是选中了的
     /// <summary>
            
    /// 初始化CheckBoxList中哪些是选中了的         
            
    /// <param name="checkList">CheckBoxList</param>
            
    /// <param name="selval">选中了的值串例如:"0,1,1,2,1"</param>
            
    /// <param name="separator">值串中使用的分割符例如"0,1,1,2,1"中的逗号</param>
            
    /// </summary>
            public static string SetChecked(CheckBoxList checkList, string selval, string separator)
            {
                
    //if (!selval.Equals(""))
                
    //{

                
    //}
                selval = separator + selval + separator;        //例如:"0,1,1,2,1"->",0,1,1,2,1,"
                for (int i = 0; i < checkList.Items.Count; i++)
                {
                    checkList.Items[i].Selected 
    = false;
                    
    string val = separator + checkList.Items[i].Value + separator;
                    
    if (selval.IndexOf(val) != -1)
                    {
                        checkList.Items[i].Selected 
    = true;
                        selval 
    = selval.Replace(val, separator);        //然后从原来的值串中删除已经选中了的
                        if (selval == separator)        //selval的最后一项也被选中的话,此时经过Replace后,只会剩下一个分隔符
                        {
                            selval 
    += separator;        //添加一个分隔符
                        }
                    }
                }
                selval 
    = selval.Substring(1, selval.Length - 2);        //除去前后加的分割符号
                return selval;
            }
  • 相关阅读:
    一个漂亮的PHP验证码
    一个漂亮的php验证码类(分享)
    PHP中exit()与die()的区别
    自定义PHP页面跳转函数redirect($url, $time = 0, $msg = '')
    MySQL时间字段究竟使用INT还是DateTime
    mysql中为int设置长度究竟是什么意思
    Array数组对象
    Math对象
    对象篇学习-字符串对象
    事件的学习
  • 原文地址:https://www.cnblogs.com/yinpeng186/p/2179016.html
Copyright © 2020-2023  润新知