管延文

管延文程序空间 QQ:27651302

导航

CheckBoxList 取值 及选中相关用法

1、取得 checkboxlist 选 中值

 

#region //处理基本设施
            string sBasicTools = "";

            for (int i = 0; i < this.CheckBoxList2.Items.Count; i++)
            {
                if (this.CheckBoxList2.Items[i].Selected == true)
                {
                    sBasicTools += this.CheckBoxList2.Items[i].Value + ",";
                }
            }

            sBasicTools = sBasicTools.TrimEnd(',');

            #endregion

 

2、根据初始值,判定 checkbox 选中项

 

            string basicdevice = dr["BasicTools"].ToString().Trim();
            string[] strtemp = basicdevice.Split(new char[] { ',' });

            foreach (string str in strtemp)
            {
                for (int i = 0; i < this.CheckBoxList2.Items.Count; i++)
                {
                    if (this.CheckBoxList2.Items[i].Value == str)
                    {
                        this.CheckBoxList2.Items[i].Selected = true;
                    }
                }
            }

3、取得首字母

 

#region 取得首字母 private static string GetGbkX(string str)

    private static string GetGbkX(string str)
    {
        if (str.CompareTo("吖") < 0) return str;
        if (str.CompareTo("八") < 0) return "A";
        if (str.CompareTo("嚓") < 0) return "B";
        if (str.CompareTo("咑") < 0) return "C";
        if (str.CompareTo("妸") < 0) return "D";
        if (str.CompareTo("发") < 0) return "E";
        if (str.CompareTo("旮") < 0) return "F";
        if (str.CompareTo("铪") < 0) return "G";
        if (str.CompareTo("讥") < 0) return "H";
        if (str.CompareTo("咔") < 0) return "J";
        if (str.CompareTo("垃") < 0) return "K";
        if (str.CompareTo("嘸") < 0) return "L";
        if (str.CompareTo("拏") < 0) return "M";
        if (str.CompareTo("噢") < 0) return "N";
        if (str.CompareTo("妑") < 0) return "O";
        if (str.CompareTo("七") < 0) return "P";
        if (str.CompareTo("亽") < 0) return "Q";
        if (str.CompareTo("仨") < 0) return "R";
        if (str.CompareTo("他") < 0) return "S";
        if (str.CompareTo("哇") < 0) return "T";
        if (str.CompareTo("夕") < 0) return "W";
        if (str.CompareTo("丫") < 0) return "X";
        if (str.CompareTo("帀") < 0) return "Y";
        if (str.CompareTo("咗") < 0) return "Z";
        return str;
    }

    #endregion

 

posted on 2011-09-29 16:09  tiger8000  阅读(4385)  评论(0)    收藏  举报