DataControlRowState 列舉

定義

指定資料控制項 (例如 DetailsViewGridView) 中資料列的狀態。

此列舉支援其成員值的位元組合。

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

欄位

Alternate 1

表示資料控制項資料列為替代資料列。

Alternate 狀態可以隨時與其他狀態結合,例如 NormalEditInsert。 如果設定,這些資料列可能會受到資料控制項的 AlternateRowStyle 屬性影響。

Edit 4

表示資料列處於編輯狀態,通常是由於按了一下資料列的編輯按鈕。 通常,EditInsert 狀態互斥 (Mutually Exclusive)。

Insert 8

表示資料列為新資料列,通常是由於按了一下插入按鈕來加入新資料列。 通常,InsertEdit 狀態互斥 (Mutually Exclusive)。

Normal 0

表示資料控制項資料列處於正常狀態。 Normal 狀態會與 Alternate 狀態以外的其他狀態互斥 (Mutually Exclusive)。

Selected 2

表示資料列已被使用者選取。

範例

下列範例示範如何使用 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 列舉來識別 或 DetailsViewRowDetailsViewRowCollection 物件的狀態 GridViewRowGridViewRowCollection 如果您要撰寫使用資料列的資料控制項,您可以使用 DataControlRowState 列舉來識別何時要呈現資料列的不同色彩, (Alternate 值) ,或啟用或停用控制項來編輯資料列 (EditInsert 值) 。

適用於

另請參閱