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 狀態可以隨時與其他狀態結合,例如 NormalEditInsertThe 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 狀態互斥 (Mutually Exclusive)。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 狀態互斥 (Mutually Exclusive)。Typically, the Insert and Edit states are mutually exclusive.

Normal 0

表示資料控制項資料列處於正常狀態。Indicates that the data control row is in a normal state. Normal 狀態會與 Alternate 狀態以外的其他狀態互斥 (Mutually Exclusive)。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. 此範例會使用位 and 運算子, 因為資料列狀態可能是一個或多個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您可以使用列舉, 在逐一GridViewRowCollection列舉或DetailsViewRowCollection集合時GridViewRow , DetailsViewRow識別或物件的狀態。You 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).

適用於

另請參閱