zoukankan      html  css  js  c++  java
  • 设置或者获取CheckboxList控件的选中值

     1.设置CheckBoxList选中的值

       /// <summary>
            /// 设置CheckBoxList中哪些是选中了的         
            /// </summary>
            /// <param name="checkList">CheckBoxList</param>
            /// <param name="selval">选中的字符串,例如:"0,1,2,3,4,4,24"</param>
            /// <param name="separator">分割字符</param>
            public void SetChecked(CheckBoxList checkList, string str, string separator)
            {
                for (int i = 0; i < checkList.Items.Count; i++)
                {
                    //checkboxList 列表中的选项值
                    string val = checkList.Items[i].Value;
                    if (val != "" && val!=null)
                    {
                        if (SplitArr(val, str, separator) >= 0)
                        {
                            checkList.Items[i].Selected = true;
                        }
                    }
                }
            }
    
            public int SplitArr(string val, string strs, string separator)
            {
                string[] arr = strs.Split(separator);
                for (int i = 0; i < arr.Length; i++)
                {
                    if (val == arr[i])
                    {
                        return i;
                    }
                }
                return -1;
            }

    2.获取CheckboxList选中了的值

     /// <summary>
            /// 获取checkboxlist的值
            /// </summary>
            /// <param name="checkList"></param>
            /// <param name="separator"></param>
            /// <returns></returns>
            public string GetChecked(CheckBoxList checkList, string separator)
            {
                string selval = "";
                for (int i = 0; i < checkList.Items.Count; i++)
                {
                    if (checkList.Items[i].Selected)
                    {
                        selval += checkList.Items[i].Value + separator;
                    }
                }
                return selval;
            }
  • 相关阅读:
    采用get方式提交数据到服务器实例
    android之HttpURLConnection
    Android中的传感器
    有符号类型无符号类型转换
    一些常用位运算示例
    C++ / CLI 调用 C++ /Native 随记
    Linux Shell Demo
    Linux Shell 脚本入门
    Linux 编译 websocket++
    Linux 编写c++程序之openssl
  • 原文地址:https://www.cnblogs.com/heluo/p/3355811.html
Copyright © 2011-2022 走看看