天天看點

上接擴充GridView控件(9) - 給資料行增加右鍵菜單

<a href="http://webabcd.blog.51cto.com/1787395/345561" target="_blank">上接&gt;&gt;</a>

2、建立一個ContextMenu實體類,有六個屬性

using System; 

using System.Collections.Generic; 

using System.Text; 

using System.ComponentModel; 

using System.Web.UI; 

namespace YYControls.SmartGridView 

        /// &lt;summary&gt; 

        /// ContextMenu 的摘要說明。 

        /// &lt;/summary&gt; 

        [ToolboxItem(false)] 

        public class ContextMenu 

        { 

                private string _icon; 

                /// &lt;summary&gt; 

                /// 文字左邊的圖示的連結 

                /// &lt;/summary&gt; 

                public string Icon 

                { 

                        get { return _icon; } 

                        set { _icon = value; } 

                } 

                private string _text; 

                /// 菜單的文字 

                public string Text 

                        get { return _text; } 

                        set { _text = value; } 

                private string _commandButtonId; 

                /// 所調用的指令按鈕的ID 

                public string CommandButtonId 

                        get { return _commandButtonId; } 

                        set { _commandButtonId = value; } 

                private string _navigateUrl; 

                /// 連結的url 

                public string NavigateUrl 

                        get { return _navigateUrl; } 

                        set { _navigateUrl = value; } 

                private ItemTypeCollection _itemType; 

                /// 右鍵菜單的項的類别 

                public ItemTypeCollection ItemType 

                        get { return _itemType; } 

                        set { _itemType = value; } 

                private TargetCollection _target; 

                /// 連結的target 

                public TargetCollection Target 

                        get { return _target; } 

                        set { _target = value; } 

                public enum ItemTypeCollection 

                        /// &lt;summary&gt; 

                        /// 連結 

                        /// &lt;/summary&gt; 

                        Link, 

                        /// 按鈕 

                        Command, 

                        /// 分隔線 

                        Separator 

                public enum TargetCollection 

                        /// 新開視窗 

                        Blank, 

                        /// 目前視窗 

                        Self, 

                        /// 跳出架構 

                        Top 

        } 

}

3、建立一個繼承自CollectionBase的類ContextMenus

using System.Collections; 

        /// ContextMenus 的摘要說明。 

        /// 注意要繼承自CollectionBase 

        [ 

        ToolboxItem(false), 

        ParseChildren(true) 

        ] 

        public class ContextMenus : CollectionBase 

                /// 構造函數 

                public ContextMenus() 

                        : base() 

                /// 實作IList接口 

                /// 擷取或設定指定索引處的元素。 

                /// &lt;param name="index"&gt;要獲得或設定的元素從零開始的索引&lt;/param&gt; 

                /// &lt;returns&gt;&lt;/returns&gt; 

                public ContextMenu this[int index] 

                        get 

                        { 

                                return (ContextMenu)base.List[index]; 

                        } 

                        set 

                                base.List[index] = (ContextMenu)value; 

                /// 将某項添加到 System.Collections.IList 中。 

                /// &lt;param name="item"&gt;要添加到 System.Collections.IList 的 System.Object。&lt;/param&gt; 

                public void Add(ContextMenu item) 

                        base.List.Add(item); 

                /// 從 System.Collections.IList 中移除特定對象的第一個比對項。 

                /// &lt;param name="index"&gt;要從 System.Collections.IList 移除的 System.Object&lt;/param&gt; 

                public void Remove(int index) 

                        if (index &gt; -1 &amp;&amp; index &lt; base.Count) 

                                base.List.RemoveAt(index); 

                /// ToString() 

                public override string ToString() 

                        return "ContextMenus"; 

4、在繼承自GridView的類中加一個複雜對象屬性,該複雜對象就是第3步建立的那個ContextMenus

private ContextMenus _contextMenus; 

                /// 行的右鍵菜單集合 

                [ 

                PersistenceMode(PersistenceMode.InnerProperty), 

                DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 

                Description("行的右鍵菜單"), 

                Category("擴充") 

                ] 

                public virtual ContextMenus ContextMenus 

                                if (_contextMenus == null) 

                                { 

                                        _contextMenus = new ContextMenus(); 

                                } 

                                return _contextMenus; 

                }

<a href="http://webabcd.blog.51cto.com/1787395/345566" target="_blank">未完待續&gt;&gt;</a>

<a href="http://webabcd.blog.51cto.com/1787395/345566" target="_blank"></a>

<a href="http://webabcd.blog.51cto.com/1787395/345566" target="_blank">     本文轉自webabcd 51CTO部落格,原文連結:http://blog.51cto.com/webabcd/345562,如需轉載請自行聯系原作者</a>

繼續閱讀