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;

  • 相关阅读:
    c++ vector容器的使用,序列倒叙reverse(),容器底部插入一个数值push_back()
    vs2015+opencv-3.2.0-vc14配置
    串的匹配算法--C语言实现
    顺序队列与链式队列--C语言实现
    链式栈-C语言实现
    顺序栈与两栈共享空间-C语言实现
    静态链表-C语言实现
    循环双向链表-C语言实现
    链表-C语言实现
    顺序表-C语言实现
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/2085528.html
Copyright © 2011-2022 走看看