2、新建一个ContextMenu实体类,有六个属性
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
namespace YYControls.SmartGridView
{
/// <summary>
/// ContextMenu 的摘要说明。
/// </summary>
[ToolboxItem( false)]
public class ContextMenu
{
private string _icon;
/// <summary>
/// 文字左边的图标的链接
/// </summary>
public string Icon
{
get { return _icon; }
set { _icon = value; }
}
private string _text;
/// <summary>
/// 菜单的文字
/// </summary>
public string Text
{
get { return _text; }
set { _text = value; }
}
private string _commandButtonId;
/// <summary>
/// 所调用的命令按钮的ID
/// </summary>
public string CommandButtonId
{
get { return _commandButtonId; }
set { _commandButtonId = value; }
}
private string _navigateUrl;
/// <summary>
/// 链接的url
/// </summary>
public string NavigateUrl
{
get { return _navigateUrl; }
set { _navigateUrl = value; }
}
private ItemTypeCollection _itemType;
/// <summary>
/// 右键菜单的项的类别
/// </summary>
public ItemTypeCollection ItemType
{
get { return _itemType; }
set { _itemType = value; }
}
private TargetCollection _target;
/// <summary>
/// 链接的target
/// </summary>
public TargetCollection Target
{
get { return _target; }
set { _target = value; }
}
/// <summary>
/// 右键菜单的项的类别
/// </summary>
public enum ItemTypeCollection
{
/// <summary>
/// 链接
/// </summary>
Link,
/// <summary>
/// 按钮
/// </summary>
Command,
/// <summary>
/// 分隔线
/// </summary>
Separator
}
/// <summary>
/// 链接的target
/// </summary>
public enum TargetCollection
{
/// <summary>
/// 新开窗口
/// </summary>
Blank,
/// <summary>
/// 当前窗口
/// </summary>
Self,
/// <summary>
/// 跳出框架
/// </summary>
Top
}
}
}
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
namespace YYControls.SmartGridView
{
/// <summary>
/// ContextMenu 的摘要说明。
/// </summary>
[ToolboxItem( false)]
public class ContextMenu
{
private string _icon;
/// <summary>
/// 文字左边的图标的链接
/// </summary>
public string Icon
{
get { return _icon; }
set { _icon = value; }
}
private string _text;
/// <summary>
/// 菜单的文字
/// </summary>
public string Text
{
get { return _text; }
set { _text = value; }
}
private string _commandButtonId;
/// <summary>
/// 所调用的命令按钮的ID
/// </summary>
public string CommandButtonId
{
get { return _commandButtonId; }
set { _commandButtonId = value; }
}
private string _navigateUrl;
/// <summary>
/// 链接的url
/// </summary>
public string NavigateUrl
{
get { return _navigateUrl; }
set { _navigateUrl = value; }
}
private ItemTypeCollection _itemType;
/// <summary>
/// 右键菜单的项的类别
/// </summary>
public ItemTypeCollection ItemType
{
get { return _itemType; }
set { _itemType = value; }
}
private TargetCollection _target;
/// <summary>
/// 链接的target
/// </summary>
public TargetCollection Target
{
get { return _target; }
set { _target = value; }
}
/// <summary>
/// 右键菜单的项的类别
/// </summary>
public enum ItemTypeCollection
{
/// <summary>
/// 链接
/// </summary>
Link,
/// <summary>
/// 按钮
/// </summary>
Command,
/// <summary>
/// 分隔线
/// </summary>
Separator
}
/// <summary>
/// 链接的target
/// </summary>
public enum TargetCollection
{
/// <summary>
/// 新开窗口
/// </summary>
Blank,
/// <summary>
/// 当前窗口
/// </summary>
Self,
/// <summary>
/// 跳出框架
/// </summary>
Top
}
}
}
3、新建一个继承自CollectionBase的类ContextMenus
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
namespace YYControls.SmartGridView
{
/// <summary>
/// ContextMenus 的摘要说明。
/// 注意要继承自CollectionBase
/// </summary>
[
ToolboxItem( false),
ParseChildren( true)
]
public class ContextMenus : CollectionBase
{
/// <summary>
/// 构造函数
/// </summary>
public ContextMenus()
: base()
{
}
/// <summary>
/// 实现IList接口
/// 获取或设置指定索引处的元素。
/// </summary>
/// <param name="index">要获得或设置的元素从零开始的索引</param>
/// <returns></returns>
public ContextMenu this[ int index]
{
get
{
return (ContextMenu) base.List[index];
}
set
{
base.List[index] = (ContextMenu)value;
}
}
/// <summary>
/// 实现IList接口
/// 将某项添加到 System.Collections.IList 中。
/// </summary>
/// <param name="item">要添加到 System.Collections.IList 的 System.Object。</param>
public void Add(ContextMenu 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);
}
}
/// <summary>
/// ToString()
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "ContextMenus";
}
}
}
using System.ComponentModel;
using System.Web.UI;
namespace YYControls.SmartGridView
{
/// <summary>
/// ContextMenus 的摘要说明。
/// 注意要继承自CollectionBase
/// </summary>
[
ToolboxItem( false),
ParseChildren( true)
]
public class ContextMenus : CollectionBase
{
/// <summary>
/// 构造函数
/// </summary>
public ContextMenus()
: base()
{
}
/// <summary>
/// 实现IList接口
/// 获取或设置指定索引处的元素。
/// </summary>
/// <param name="index">要获得或设置的元素从零开始的索引</param>
/// <returns></returns>
public ContextMenu this[ int index]
{
get
{
return (ContextMenu) base.List[index];
}
set
{
base.List[index] = (ContextMenu)value;
}
}
/// <summary>
/// 实现IList接口
/// 将某项添加到 System.Collections.IList 中。
/// </summary>
/// <param name="item">要添加到 System.Collections.IList 的 System.Object。</param>
public void Add(ContextMenu 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);
}
}
/// <summary>
/// ToString()
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "ContextMenus";
}
}
}
4、在继承自GridView的类中加一个复杂对象属性,该复杂对象就是第3步创建的那个ContextMenus
private ContextMenus _contextMenus;
/// <summary>
/// 行的右键菜单集合
/// </summary>
[
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Description( "行的右键菜单"),
Category( "扩展")
]
public virtual ContextMenus ContextMenus
{
get
{
if (_contextMenus == null)
{
_contextMenus = new ContextMenus();
}
return _contextMenus;
}
}
/// <summary>
/// 行的右键菜单集合
/// </summary>
[
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Description( "行的右键菜单"),
Category( "扩展")
]
public virtual ContextMenus ContextMenus
{
get
{
if (_contextMenus == null)
{
_contextMenus = new ContextMenus();
}
return _contextMenus;
}
}