This documentation is archived and is not being maintained.

DataControlRowType Enumeration

Updated: July 2008

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

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

Public Enumeration DataControlRowType
Dim instance As DataControlRowType

Member nameDescription
HeaderA header row of a data control. Header rows cannot be data-bound.
FooterA footer row of a data control. Footer rows cannot be data-bound.
DataRowA data row of a data control. Only DataRow rows can be data-bound.
SeparatorA row separator. Row separators cannot be data-bound.
PagerA row that displays pager buttons or a pager control. Pager rows cannot be data-bound.
EmptyDataRowThe empty row of a data-bound control. The empty row is displayed when the data-bound control has no records to display and the EmptyDataTemplate template is not Nothing.

The DataControlRowType enumeration identifies the function of rows in a data control. It is used by the DetailsView and GridView controls to distinguish between rows that display data and rows that display other user interface (UI) elements, such as a header row, row separator, or pager buttons.

You can use the DataControlRowType enumeration to identify the type of a GridViewRow or DetailsViewRow object when you enumerate through a GridViewRowCollection or DetailsViewRowCollection collection. If you are writing a data control that creates rows, you can use the DataControlRowType enumeration to identify the function of different rows in the control.

The following code example demonstrates how to use the DataControlRowType enumeration to check the type of a row when working with a GridView control. The AuthorsGridView_RowCreated method ensures that the CommandArgument property of a LinkButton control is unique for all the data rows in the GridView control, so that when a row's LinkButton control is clicked, it can be identified correctly.

<%@ Page language="VB" %>

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

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Create a new GridView object. 
    Dim customersGridView As New GridView()

    ' Set the GridView object's properties.
    customersGridView.ID = "CustomersGridView"
    customersGridView.DataSourceID = "CustomersSource"
    customersGridView.AutoGenerateColumns = False 

    ' Dynamically create the columns for the GridView control. 
    Dim addColumn As New ButtonField()
    addColumn.CommandName = "Add"
    addColumn.Text = "Add"
    addColumn.ButtonType = ButtonType.Link

    Dim companyNameColumn As New BoundField()
    companyNameColumn.DataField = "CompanyName"
    companyNameColumn.HeaderText = "Company Name" 

    Dim cityColumn As New BoundField()
    cityColumn.DataField = "City"
    cityColumn.HeaderText = "City" 

    ' Add the columns to the Columns collection 
    ' of the GridView control.

    ' Programmatically register the event handling methods. 
    AddHandler customersGridView.RowCommand, AddressOf CustomersGridView_RowCommand
    AddHandler customersGridView.RowCreated, AddressOf CustomersGridView_RowCreated

    ' Add the GridView object to the Controls collection 
    ' of the PlaceHolder control.

  End Sub 

  Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

    ' If multiple ButtonField columns are used, use the 
    ' CommandName property to determine which button was clicked. 
    If e.CommandName = "Add" Then 

      ' Convert the row index stored in the CommandArgument 
      ' property to an Integer. 
      Dim index As Integer = Convert.ToInt32(e.CommandArgument)

      ' Retrieve the row that contains the button clicked 
      ' by the user from the Rows collection. Use the 
      ' CommandSource property to access the GridView control. 
      Dim customersGridView As GridView = CType(e.CommandSource, GridView)
      Dim row As GridViewRow = customersGridView.Rows(index)

      ' Create a new ListItem object for the customer in the row. 
      Dim item As New ListItem()
      item.Text = Server.HtmlDecode(row.Cells(1).Text) + " " + Server.HtmlDecode(row.Cells(2).Text)

      ' If the author is not already in the ListBox, add the ListItem 
      ' object to the Items collection of a ListBox control. 
      If Not CustomersListBox.Items.Contains(item) Then


      End If 
    End If 

  End Sub 

  Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    ' The GridViewCommandEventArgs class does not contain a 
    ' property that indicates which row's command button was 
    ' clicked. To identify which row was clicked, use the button's 
    ' CommandArgument property by setting it to the row's index. 
    If e.Row.RowType = DataControlRowType.DataRow Then 

      ' Retrieve the LinkButton control from the first column. 
      Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)

      ' Set the LinkButton's CommandArgument property with the 
      ' row's index.
      addButton.CommandArgument = e.Row.RowIndex.ToString()

    End If 

  End Sub


<html xmlns="" >
  <head runat="server">
    <title>GridViewCommandEventArgs Example</title>
    <form id="form1" runat="server">

      <h3>GridViewCommandEventArgs Example</h3>

      <table width="100%">
          <td style="width:50%">
            <asp:placeholder id="GridViewPlaceHolder"

          <td style="vertical-align:top; width:50%">
             Customers: <br/>
             <asp:listbox id="CustomersListBox"

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0




July 2008

Fixed description for one of the members.

Content bug fix.