Export (0) Print
Expand All
Expand Minimize
0 out of 3 rated this helpful - Rate this topic

DataControlRowState Enumeration

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.

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

[FlagsAttribute] 
public enum DataControlRowState
/** @attribute FlagsAttribute() */ 
public enum DataControlRowState
FlagsAttribute 
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;
  }

  cell.Controls.Add(radio);
}

// This method adds a RadioButton control and any other content to the
//cell's Controls collection.
protected 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 (get_DataField().get_Length() != 0) {
        radio.add_DataBinding(new EventHandler(this.OnDataBindField));
    }
    radio.set_Text(this.get_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.set_Enabled(false);
    // If the row is in edit mode, enable the button.
    if (((int)(rowState & DataControlRowState.Edit) != 0) || ((int)(
        rowState & DataControlRowState.Insert) != 0)) {
        radio.set_Enabled(true);
    }
    cell.get_Controls().Add(radio);
} //InitializeDataCell

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.