上接擴展GridView控件(4) - 聯動複選框(複選框的全選和取消全選)

 
 
四、新建一個繼承自CollectionBase的類CheckboxAlls
using System.Collections;
using System.ComponentModel;
using System.Web.UI;

namespace YYControls.SmartGridView
{
         /// <summary>
         /// CheckboxAlls 的摘要說明。
         /// 注意要繼承自CollectionBase
         /// </summary>
        [
        ToolboxItem( false),
        ParseChildren( true)
        ]
         public class CheckboxAlls : CollectionBase
        {
                 /// <summary>
                 /// 構造函數
                 /// </summary>
                 public CheckboxAlls()
                        : base()
                {
                }

                 /// <summary>
                 /// 實現IList接口
                 /// 獲取或設置指定索引處的元素。
                 /// </summary>
                 /// <param name="index">要得到或設置的元素從零開始的索引</param>
                 /// <returns></returns>
                 public CheckboxAll this[ int index]
                {
                        get
                        {
                                 return (CheckboxAll) base.List[index];
                        }
                        set
                        {
                                 base.List[index] = (CheckboxAll)value;
                        }
                }

                 /// <summary>
                 /// 實現IList接口
                 /// 將某項添加到 System.Collections.IList 中。
                 /// </summary>
                 /// <param name="item">要添加到 System.Collections.IList 的 System.Object。</param>
                 public void Add(CheckboxAll item)
                {
                         base.List.Add(item);
                }

                 /// <summary>
                 /// 實現IList接口
                 /// 從 System.Collections.IList 中移除特定對象的第一個匹配項。
                 /// </summary>
                 /// <param name="index">要從 System.Collections.IList 移除的 System.Object</param>
                 public void Remove( int index)
                {
                         if (index > -1 && index < base.Count)
                        {
                                 base.List.RemoveAt(index);
                        }
                }
        }
}
 
 
五、在繼承自GridView的類中加一個複雜對象屬性,該複雜對象就是第4步建立的那個CheckboxAlls
private CheckboxAlls _checkboxAlls;
                 /// <summary>
                 /// 複選框組集合 一個組由一個 全選複選框 和多個 項複選框組成
                 /// </summary>
                [
                PersistenceMode(PersistenceMode.InnerProperty),
                DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
                Description( "複選框組集合 一個組由一個 全選複選框 和多個 項複選框組成"),
                Category( "擴展")
                ]
                 public virtual CheckboxAlls CheckboxAlls
                {
                        get
                        {
                                 if (_checkboxAlls == null)
                                {
                                        _checkboxAlls = new CheckboxAlls();
                                }
                                 return _checkboxAlls;
                        }
                }
 

六、聲明一些內部屬性
/// <summary>
                 /// 隱藏字段的ID,用於存每組的全選複選框ID
                 /// </summary>
                 protected string HiddenCheckboxAllID
                {
                        get { return "hdn_checkboxAll"; }
                }
                 /// <summary>
                 /// 隱藏字段的ID,用於存每組的項複選框ID
                 /// </summary>
                 protected string HiddenCheckboxItemID
                {
                        get { return "hdn_checkboxItem"; }
                }

                 /// <summary>
                 /// 組分隔符,一個 全選複選框 和其對應的n個 項複選框 爲一個組
                 /// </summary>
                 protected char GroupSeparator
                {
                        get { return ','; }
                }
                 /// <summary>
                 /// 項分隔符,項複選框 每一個項之間的分隔符
                 /// </summary>
                 protected char ItemSeparator
                {
                        get { return '|'; }
                }
 
 
 
相關文章
相關標籤/搜索