DataControlRowState 枚举

定义

指定数据控件(例如 DetailsViewGridView)中行的状态。Specifies the state of a row in a data control, such as DetailsView or GridView.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

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

字段

Alternate 1

指示该数据控件行是交替行。Indicates that the data control row is an alternate row.

可随时将 Alternate 状态与其他状态(如 NormalEditInsert)合并。The Alternate state can be combined with other states, such as Normal, Edit, or Insert, at any time. 数据控件的 AlternateRowStyle 属性(若设置)可能会影响这些行。These rows might be affected by the AlternateRowStyle property of the data control, if set.

Edit 4

指示该行处于编辑状态,这通常是单击行的“编辑”按钮的结果。Indicates that the row is in an edit state, often the result of clicking an edit button for the row. 通常,EditInsert 状态互相排斥。Typically, the Edit and Insert states are mutually exclusive.

Insert 8

指示该行是新行,这通常是单击“插入”按钮添加新行的结果。Indicates that the row is a new row, often the result of clicking an insert button to add a new row. 通常,InsertEdit 状态互相排斥。Typically, the Insert and Edit states are mutually exclusive.

Normal 0

指示该数据控件行处于正常状态。Indicates that the data control row is in a normal state. Normal 状态与其他状态相互排斥,但 Alternate 状态除外。The Normal state is mutually exclusive with other states except the Alternate state.

Selected 2

指示该行已被用户选定。Indicates that the row has been selected by the user.

示例

下面的示例演示如何使用DataControlRowState枚举基于GridView控件中行的状态来呈现用户界面 (UI)。The following example demonstrates how to use the DataControlRowState enumeration to render a user interface (UI) based on the state of a row in a GridView control. 类, 它是CheckBoxField从控件派生的自定义字段控件, GridView为控件中的每一行呈现数据绑定单选按钮。 RadioButtonFieldThe RadioButtonField class, which is a custom field control that derives from the CheckBoxField control, renders a data-bound radio button for every row in a GridView control. 当行向用户显示数据并且未处于编辑模式时, 将禁用该RadioButton控件。When the row is displaying data to a user and is not in edit mode, the RadioButton control is disabled. 当用户更新中GridView的行, 并且该行处于编辑模式时, 该RadioButton控件将呈现为已启用, 以便可以单击它。When the user updates a row in GridView and the row is in edit mode, the RadioButton control is rendered as enabled so that it can be clicked. 该示例使用按位 "与" 运算符, 因为行状态可能是一个或多个DataControlRowState值的组合。The example uses bitwise AND operators, because the row state might be a combination of one or more DataControlRowState values. 此示例是为DataControlField类提供的更大示例的一部分。This example is part of a larger example provided for the DataControlField class.

// 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

注解

枚举标识数据控件DetailsView (例如或GridView) 中某行的状态。 DataControlRowStateThe DataControlRowState enumeration identifies the state of a row in a data control such as DetailsView or GridView. 行的状态可以是DataControlRowState值的组合或值的组合, 因此, 请使用按位运算来确定行的状态是否DataControlRowState包含值而不是等效测试。A row's state can be one or a combination of the DataControlRowState values, so use bitwise operations to determine whether the state of the row includes a DataControlRowState value, rather than an equivalence test. 枚举用于任何类型的行, 而不仅仅DataRow是行 (通常情况下, 标头行和表尾行的状态设置为Normal)。 DataControlRowStateThe DataControlRowState enumeration is used for any type of row, not just DataRow rows (typically, the state of header and footer rows is set to Normal).

DataControlRowState在枚举DetailsViewRow GridViewRow或集合DetailsViewRowCollection时, 可以使用枚举来标识或对象的状态。 GridViewRowCollectionYou can use the DataControlRowState enumeration to identify the state of a GridViewRow or DetailsViewRow object when enumerating through a GridViewRowCollection or DetailsViewRowCollection collection, respectively. 如果你正在编写使用行的数据控件, 则可以使用DataControlRowState枚举来确定何时为行Alternate (值) 呈现不同的颜色, 或者为启用或禁用以Edit编辑行的控件 (和Insert值)。If you are writing a data control that uses rows, you can use the DataControlRowState enumeration to identify when to render different colors for a row (the Alternate value), or controls that are enabled or disabled for editing a row (the Edit and Insert values).

适用于

另请参阅