zoukankan      html  css  js  c++  java
  • CheckBoxList 拓展

    让保存和反绑定更加简单!





    新建 ZCheckBoxList类:

    using System.Web.UI.WebControls;
    
    namespace Business
    
    {
    
        public class ZCheckBoxList : CheckBoxList
    
        {
    
            /// 2011-6-19 曾祥展  
    
            /// 假如勾2,3,4 則SelectedValue="2,3,4"
    
            /// </remarks>
    
            public override string SelectedValue
    
            {
    
                get
    
                {
    
                    string _ReturnValue = "";
    
                    this.EnsureChildControls();
    
    
    
                    for (int i = 0; i < this.Items.Count; i++)
    
                    {
    
                        if (this.Items[i].Selected == true)
    
                        {
    
                            _ReturnValue += this.Items[i].Value + ",";
    
                        }
    
                    }
    
                    if (!string.IsNullOrEmpty(_ReturnValue))
    
                    {
    
                        _ReturnValue = _ReturnValue.TrimEnd(',');
    
                    }
    
                    else
    
                    {
    
                        return string.Empty;
    
                    }
    
    
    
                    return _ReturnValue;
    
                }
    
    
    
                set
    
                {
    
                    if (value == null)
    
                    {
    
                        value = string.Empty;
    
                    }
    
                    string _ReturnValue = "";
    
    
    
                    this.EnsureChildControls();
    
                    _ReturnValue = value;
    
    
    
    
    
                    for (int i = 0; i < this.Items.Count; i++)
    
                    {
    
                        this.Items[i].Selected = false;
    
                    }
    
    
    
                    if (_ReturnValue.Trim().Length != 0)
    
                    {
    
                        string[] ReturnValue1 = _ReturnValue.Split(',');
    
                        // 1,2,3
    
                        for (int intItem = 0; intItem <= ReturnValue1.Length - 1; intItem++)
    
                        {
    
                            for (int i = 0; i < this.Items.Count; i++)
    
                            {
    
                                if (ReturnValue1[intItem] == this.Items[i].Value)
    
                                {
    
                                    this.Items[i].Selected = true;
    
                                    break;
    
                                }
    
                            }
    
                        }
    
                    }
    
                }
    
            }
    
    
    
    
    
        }
    
    }



    <%@ Register Assembly="Business" Namespace="Business" TagPrefix="cc1" %>
    
    
    
    <cc1:ZCheckBoxList ID="cblEnvironment" runat="server"
    
         RepeatDirection="Horizontal" RepeatColumns="3">
    
     </cc1:ZCheckBoxList>
    
     
    取值:
    this.cblEnvironment.SelectedValue
    赋值:
     cblEnvironment.SelectedValue = eid;

  • 相关阅读:
    Vue.js监听事件
    Vue.js组件传值
    Vue.js安装
    C#中输入法全角转换半角
    文件夹操作
    转JSON字符串,并进行AES加密
    ReportView报表的使用
    c++读入优化
    快读板子
    【转】2020年 大二上 ACM
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/2085528.html
Copyright © 2011-2022 走看看