扩展GridView控件-改变选中的行的样式
[IT168 技术文档]扩展GridView控件(七)——改变通过CheckBox选中的行的样式
作者:webabcd
介绍
在GridView中如果每行都有复选框的话,选中了某个复选框则修改该复选框所在行的样式,这是经常要用到的功能,因此我们来扩展一下GridView控件。
控件开发
1、新建一个继承自GridView的类。

/**//// <summary>
/// 继承自GridView
/// </summary>
[ToolboxData(@"<{0}:SmartGridView runat='server'></{0}:SmartGridView>")]
public class SmartGridView : GridView


{
}
2、新建一个ChangeRowCSSByCheckBox实体类,有两个属性
using System;
using System.Collections.Generic;
using System.Text;

using System.ComponentModel;

namespace YYControls.SmartGridView


{

/**//// <summary>
/// 通过行的CheckBox的选中与否来修改行的样式
/// 实体类
/// </summary>
[TypeConverter(typeof(ExpandableObjectConverter))]
public class ChangeRowCSSByCheckBox

{
private string _checkBoxID;

/**//// <summary>
/// 根据哪个ChecxBox来判断是否选中了行,指定该CheckBox的ID
/// </summary>
[
Description("根据哪个ChecxBox来判断是否选中了行,指定该CheckBox的ID"),
Category("扩展"),
DefaultValue(""),
NotifyParentProperty(true)
]
public string CheckBoxID

{

get
{ return _checkBoxID; }

set
{ _checkBoxID = value; }
}

private string _cssClassRowSelected;

/**//// <summary>
/// 选中行的样式的 CSS 类名
/// </summary>
[
Description("选中行的样式的 CSS 类名"),
Category("扩展"),
DefaultValue(""),
NotifyParentProperty(true)
]
public string CssClassRowSelected

{

get
{ return _cssClassRowSelected; }

set
{ _cssClassRowSelected = value; }
}


/**//// <summary>
/// ToString()
/// </summary>
/// <returns></returns>
public override string ToString()

{
return "ChangeRowCSSByCheckBox";
}
}
}
private ChangeRowCSSByCheckBox _changeRowCSSByCheckBox;

/**//// <summary>
/// 通过行的CheckBox的选中与否来修改行的样式
/// </summary>
[
Description("通过行的CheckBox的选中与否来修改行的样式"),
Category("扩展"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty)
]
public virtual ChangeRowCSSByCheckBox ChangeRowCSSByCheckBox

{
get

{
if (_changeRowCSSByCheckBox == null)

{
_changeRowCSSByCheckBox = new ChangeRowCSSByCheckBox();
}
return _changeRowCSSByCheckBox;
}
}
作者:webabcd
介绍
在GridView中如果每行都有复选框的话,选中了某个复选框则修改该复选框所在行的样式,这是经常要用到的功能,因此我们来扩展一下GridView控件。
控件开发
1、新建一个继承自GridView的类。

/**//// <summary>
/// 继承自GridView
/// </summary>
[ToolboxData(@"<{0}:SmartGridView runat='server'></{0}:SmartGridView>")]
public class SmartGridView : GridView

{
}2、新建一个ChangeRowCSSByCheckBox实体类,有两个属性
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace YYControls.SmartGridView

{
/**//// <summary>
/// 通过行的CheckBox的选中与否来修改行的样式
/// 实体类
/// </summary>
[TypeConverter(typeof(ExpandableObjectConverter))]
public class ChangeRowCSSByCheckBox
{
private string _checkBoxID;
/**//// <summary>
/// 根据哪个ChecxBox来判断是否选中了行,指定该CheckBox的ID
/// </summary>
[
Description("根据哪个ChecxBox来判断是否选中了行,指定该CheckBox的ID"),
Category("扩展"),
DefaultValue(""),
NotifyParentProperty(true)
]
public string CheckBoxID
{
get
{ return _checkBoxID; }
set
{ _checkBoxID = value; }
}
private string _cssClassRowSelected;
/**//// <summary>
/// 选中行的样式的 CSS 类名
/// </summary>
[
Description("选中行的样式的 CSS 类名"),
Category("扩展"),
DefaultValue(""),
NotifyParentProperty(true)
]
public string CssClassRowSelected
{
get
{ return _cssClassRowSelected; }
set
{ _cssClassRowSelected = value; }
}

/**//// <summary>
/// ToString()
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "ChangeRowCSSByCheckBox";
}
}
}
3、在继承自GridView的类中加一个复杂对象属性,该复杂对象就是第2步创建的那个ChangeRowCSSByCheckBox
private ChangeRowCSSByCheckBox _changeRowCSSByCheckBox;
/**//// <summary>
/// 通过行的CheckBox的选中与否来修改行的样式
/// </summary>
[
Description("通过行的CheckBox的选中与否来修改行的样式"),
Category("扩展"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty)
]
public virtual ChangeRowCSSByCheckBox ChangeRowCSSByCheckBox
{
get
{
if (_changeRowCSSByCheckBox == null)
{
_changeRowCSSByCheckBox = new ChangeRowCSSByCheckBox();
}
return _changeRowCSSByCheckBox;
}
}
0
相关文章