Export (0) Print
Expand All

GridViewRow Class

Note: This class is new in the .NET Framework version 2.0.

Represents an individual row in a GridView control.

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

public ref class GridViewRow : public TableRow, IDataItemContainer, INamingContainer
public class GridViewRow extends TableRow implements IDataItemContainer, INamingContainer
public class GridViewRow extends TableRow implements IDataItemContainer, INamingContainer

The GridViewRow class is used represent an individual row in a GridView control. Each row in the GridView control has a designated row type. The following table lists the different row types.

Row type

Description

DataGridRowType.DataRow

A data row in the GridView control.

DataGridRowType.Footer

The footer row in the GridView control.

DataGridRowType.Header

The header row in the GridView control.

DataGridRowType.NullRow

The null row in the GridView control. The null row is displayed in a GridView control when there are no records to display.

DataGridRowType.Pager

A pager row in the GridView control.

DataGridRowType.Separator

A separator row in the GridView control.

To determine the row type of a GridViewRow object, use the RowType property. A GridViewRow object also has a state associated with it. The state can be a bitwise combination of the values in the following table.

State value

Description

DataControlRowState.Alternate

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

DataControlRowState.Edit

The GridViewRow object is in edit mode.

DataControlRowState.Normal

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

DataControlRowState.Selected

The GridViewRow object is selected.

To determine the state of a GridViewRow object, use the RowState property.

The GridView control stores all of its data rows in the Rows collection. To determine the index of a GridViewRow object in the Rows collection, use the RowIndex property.

You can access the properties of the underlying data object that is bound to the GridViewRow object by using the DataItem property.

NoteNote

The DataItem property is only available during and after the RowDataBound event of a GridView control.

To determine the index of the data object in the underlying data source, use the DataItemIndex property.

You can access the individual cells of the GridViewRow object by using the Cells property. If a cell contains other controls, you can retrieve a control from the cell by using the Controls collection of the cell. You can also use the FindControl method of the cell to find the control, if the control has an ID specified.

To retrieve a field value from a BoundField field column or an automatically generated field column, use the Text property of the cell. To retrieve a field value from other field column types where the field value is bound to a control, first retrieve the control from the appropriate cell and then access the appropriate property of the control.

NoteNote

It is possible to use a data-binding expression directly in a TemplateField field column without binding the value to a property of a control. In this case, the field value is automatically placed in a DataBoundLiteralControl control. To retrieve the field value, you must first retrieve the DataBoundLiteralControl control from the appropriate cell and then use its Text property.

For a list of initial property values for an instance of GridViewRow, see the GridViewRow constructor.

The following example demonstrates how to use a GridViewRow object to retrieve a field value from a cell in the GridView control and then display the value on the page.

No code example is currently available or this language may not be supported.

The following example demonstrates how to use a GridViewRow object to retrieve a TextBox control declared in a TemplateField field column's edit item template. The value of the text box is then passed to a SqlDataSource control for updating in the data source.

No code example is currently available or this language may not be supported.

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.TableRow
        System.Web.UI.WebControls.GridViewRow

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft