Export (0) Print
Expand All
Expand Minimize

DataControlRowState Enumeration

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


Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public enum DataControlRowState

Member nameDescription
AlternateIndicates 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.

EditIndicates 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.
InsertIndicates 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.
NormalIndicates that the data control row is in a normal state. The Normal state is mutually exclusive with other states except the Alternate state.
SelectedIndicates that the row has been selected by the user.

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

The following code 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 code 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;


.NET Framework




© 2014 Microsoft