DataControlRowState 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定数据控件中行的状态,例如 DetailsView 或 GridView。
此枚举支持其成员值的按位组合。
public enum class DataControlRowState
[System.Flags]
public enum DataControlRowState
[<System.Flags>]
type DataControlRowState =
Public Enum DataControlRowState
- 继承
- 属性
字段
| 名称 | 值 | 说明 |
|---|---|---|
| Normal | 0 | |
| Alternate | 1 | 指示数据控制行是备用行。 该 |
| Selected | 2 | 指示用户已选择该行。 |
| Edit | 4 | |
| Insert | 8 |
示例
以下示例演示如何使用 DataControlRowState 枚举基于控件中 GridView 行的状态呈现用户界面(UI)。 该 RadioButtonField 类是派生自控件的 CheckBoxField 自定义字段控件,它为控件中的每个 GridView 行呈现数据绑定单选按钮。 当行向用户显示数据且未处于编辑模式时,控件 RadioButton 将被禁用。 当用户更新行并且 GridView 行处于编辑模式时,控件 RadioButton 将呈现为启用状态,以便单击该控件。 该示例使用按位 AND 运算符,因为行状态可能是一个或多个 DataControlRowState 值的组合。 此示例是DataControlField类所提供的一个大型示例的一部分。
// This method adds a RadioButton control and any other
// content to the cell's Controls collection.
protected override void InitializeDataCell
(DataControlFieldCell cell, DataControlRowState rowState) {
RadioButton radio = new RadioButton();
// If the RadioButton is bound to a DataField, add
// the OnDataBindingField method event handler to the
// DataBinding event.
if (DataField.Length != 0) {
radio.DataBinding += new EventHandler(this.OnDataBindField);
}
radio.Text = this.Text;
// Because the RadioButtonField is a BoundField, it only
// displays data. Therefore, unless the row is in edit mode,
// the RadioButton is displayed as disabled.
radio.Enabled = false;
// If the row is in edit mode, enable the button.
if ((rowState & DataControlRowState.Edit) != 0 ||
(rowState & DataControlRowState.Insert) != 0) {
radio.Enabled = true;
}
cell.Controls.Add(radio);
}
' This method adds a RadioButton control and any other
' content to the cell's Controls collection.
Protected Overrides Sub InitializeDataCell( _
ByVal cell As DataControlFieldCell, _
ByVal rowState As DataControlRowState)
Dim radio As New RadioButton()
' If the RadioButton is bound to a DataField, add
' the OnDataBindingField method event handler to the
' DataBinding event.
If DataField.Length <> 0 Then
AddHandler radio.DataBinding, AddressOf Me.OnDataBindField
End If
radio.Text = Me.Text
' Because the RadioButtonField is a BoundField, it only
' displays data. Therefore, unless the row is in edit mode,
' the RadioButton is displayed as disabled.
radio.Enabled = False
' If the row is in edit mode, enable the button.
If (rowState And DataControlRowState.Edit) <> 0 _
OrElse (rowState And DataControlRowState.Insert) <> 0 Then
radio.Enabled = True
End If
cell.Controls.Add(radio)
End Sub
注解
枚举 DataControlRowState 标识数据控件中某行的状态,例如 DetailsView 或 GridView。 行的状态可以是值之一或组合 DataControlRowState ,因此使用按位运算来确定行的状态是否包括值 DataControlRowState ,而不是等效性测试。
DataControlRowState枚举用于任何类型的行,而不仅仅是DataRow行(通常,页眉和页脚行的状态设置为Normal)。
在分别通过或集合进行枚举时,可以使用DataControlRowState枚举来标识或GridViewRowDetailsViewRow对象的状态GridViewRowCollection。DetailsViewRowCollection 如果要编写使用行的数据控件,则可以使用 DataControlRowState 枚举来标识何时为行( Alternate 值)或启用或禁用的控件呈现不同的颜色来编辑行( Edit 和 Insert 值)。