DataControlRowState 枚举

定义

指定数据控件中行的状态,例如 DetailsViewGridView

此枚举支持其成员值的按位组合。

public enum class DataControlRowState
[System.Flags]
public enum DataControlRowState
[<System.Flags>]
type DataControlRowState = 
Public Enum DataControlRowState
继承
DataControlRowState
属性

字段

名称 说明
Normal 0

指示数据控制行处于正常状态。 该 Normal 状态与其他状态互斥,但状态 Alternate 除外。

Alternate 1

指示数据控制行是备用行。

Alternate 状态可以与其他状态(例如 NormalEditInsert)随时结合使用。 如果已设置,这些行可能会受到 AlternateRowStyle 数据控件的属性的影响。

Selected 2

指示用户已选择该行。

Edit 4

指示行处于编辑状态,通常是单击行的编辑按钮的结果。 通常, Edit 状态 Insert 是相互排斥的。

Insert 8

指示该行是新行,通常是单击插入按钮添加新行的结果。 通常, Insert 状态 Edit 是相互排斥的。

示例

以下示例演示如何使用 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 标识数据控件中某行的状态,例如 DetailsViewGridView。 行的状态可以是值之一或组合 DataControlRowState ,因此使用按位运算来确定行的状态是否包括值 DataControlRowState ,而不是等效性测试。 DataControlRowState枚举用于任何类型的行,而不仅仅是DataRow行(通常,页眉和页脚行的状态设置为Normal)。

在分别通过或集合进行枚举时,可以使用DataControlRowState枚举来标识或GridViewRowDetailsViewRow对象的状态GridViewRowCollectionDetailsViewRowCollection 如果要编写使用行的数据控件,则可以使用 DataControlRowState 枚举来标识何时为行( Alternate 值)或启用或禁用的控件呈现不同的颜色来编辑行( EditInsert 值)。

适用于

另请参阅