Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
RowState Property

GridViewRow.RowState Property

Gets the state of the GridViewRow object.

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

public virtual DataControlRowState RowState { get; set; }
<asp:GridViewRow RowState="DataControlRowState" />

Property Value

Type: System.Web.UI.WebControls.DataControlRowState
A bitwise combination of the DataControlRowState values.

Use the RowType property to determine the state of the GridViewRow object. The state can be a bitwise combination of the values in the following table:

Status value



The GridViewRow object is an alternate row in the GridView control.


The GridViewRow object is in edit mode.


The GridViewRow object is in its normal (default) state.


The GridViewRow object is selected.

This property is commonly used to determine the state of a row before performing an operation.

The following example demonstrates how to use the RowState property to determine whether a row is in edit mode or is selected. If the user selects a different row while the GridView control is in edit mode, the GridView control exits edit mode.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void AuthorsGridView_SelectedIndexChanged(Object sender, EventArgs e)

    // Get the selected row.
    GridViewRow row = AuthorsGridView.SelectedRow;

    // Check the row state. If the row is not in edit mode and is selected,
    // exit edit mode. This ensures that the GridView control exits edit mode
    // when a user selects a different row while the GridView control is in 
    // edit mode. Notice that the DataControlRowState enumeration is a flag
    // enumeration, which means that you can combine values using bitwise
    // operations.
    if(row.RowState != (DataControlRowState.Edit|DataControlRowState.Selected))
      AuthorsGridView.EditIndex = -1;


  void AuthorsGridView_RowEditing(Object sender, GridViewEditEventArgs e)

    // Get the row being edited.
    GridViewRow row = AuthorsGridView.Rows[e.NewEditIndex];

    // Check the row state. If the row is not in edit mode and is selected,
    // select the current row. This ensures that the GridView control selects
    // the current row when the user clicks the Edit button.
    if(row.RowState != (DataControlRowState.Edit|DataControlRowState.Selected))
      AuthorsGridView.SelectedIndex = e.NewEditIndex;



<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridViewRow RowState Example</title>
    <form id="form1" runat="server">

      <h3>GridViewRow RowState Example</h3>

      <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames attribute as read-only    -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="AuthorsGridView" 

        <selectedrowstyle backcolor="Yellow"/>


          <asp:boundfield datafield="au_lname"
            headertext="Last Name"/>
          <asp:boundfield datafield="au_fname"
            headertext="First Name"/> 



      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_id], [au_lname], [au_fname] FROM [authors]"             
        updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)" 
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft