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;

  • 相关阅读:
    Sprinig.net 双向绑定 Bidirectional data binding and data model management 和 UpdatePanel
    Memcached是什么
    Spring.net 网络示例 codeproject
    jquery.modalbox.show 插件
    UVA 639 Don't Get Rooked
    UVA 539 The Settlers of Catan
    UVA 301 Transportation
    UVA 331 Mapping the Swaps
    UVA 216 Getting in Line
    UVA 10344 23 out of 5
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/2085528.html
Copyright © 2011-2022 走看看