GridViewRow Class
Updated: July 2008
Represents an individual row in a GridView control.
Assembly: System.Web (in System.Web.dll)
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class GridViewRow : public TableRow, IDataItemContainer, INamingContainer
<asp:GridViewRow />
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 |
|---|---|
A data row in the GridView control. | |
The empty row in the GridView control. The empty row is displayed when the GridView control has no records to display and the GridView::EmptyDataTemplate template is not nullptr. | |
The footer row in the GridView control. | |
The header row in the GridView control. | |
A pager row in the GridView control. | |
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 |
|---|---|
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. |
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.
Note: |
|---|
The DataItem property is available only 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.
Note: |
|---|
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.
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.
Security Note: |
|---|
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview. |
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI::Control
System.Web.UI.WebControls::WebControl
System.Web.UI.WebControls::TableRow
System.Web.UI.WebControls::GridViewRow
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.
Note:
Security Note: