DataControlRowState Enum

Definition

Specifies the state of a row in a data control, such as DetailsView or GridView.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

public enum class DataControlRowState
[System.Flags]
public enum DataControlRowState
type DataControlRowState = 
Public Enum DataControlRowState
Inheritance
DataControlRowState
Attributes

Fields

Alternate 1

Indicates that the data control row is an alternate row.

The Alternate state can be combined with other states, such as Normal, Edit, or Insert, at any time. 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. 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. Typically, the Insert and Edit states are mutually exclusive.

Normal 0

Indicates that the data control row is in a normal state. 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.

Examples

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. The 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. When the row is displaying data to a user and is not in edit mode, the RadioButton control is disabled. 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. The example uses bitwise AND operators, because the row state might be a combination of one or more DataControlRowState values. 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

Remarks

The DataControlRowState enumeration identifies the state of a row in a data control such as DetailsView or GridView. 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. The 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).

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. 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).

Applies to

See also