System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Returns the collection of GridViewRow objects that represent the data rows in a GridView control.
Script |
[ GridViewRowCollection variable = ] GridView.Rows |
The property is read only with no default value.
The Rows collection provides a way to programmatically obtain information about each data-bound row in a GridView control.
When a data source is bound to a GridView, the Rows collection is populated with one GridViewRow object for each record ( or row of data ) in the data source.
NOTE: Only rows bound to the data source ( rows with their RowType property set to DataControlRowType.DataRow ) are contained in the Rows collection. The header, footer, and separator rows are not included.
The Rows collection does not provide any methods to add or remove rows in the collection. However, you can control the contents of a row by providing a handler for the RowCreated event.
The following example show how to programmatically access the Rows collection to retrieve and display the Text of the DataBoundLiteralControl associated with each item in a GridView control.
void getRows ( Object src, EventArgs e ) {
foreach ( GridViewRow row in myGrid.Rows ) {
message.Text += "<br>" + row.Cells [ 0 ].Text +
", " + row.Cells [ 1 ].Text +
", " + row.Cells [ 2 ].Text;
}
}
Sub getRows ( src As Object, e As EventArgs )
Dim row As GridViewRow
For Each row In myGrid.Rows
message.Text += "<br>" + row.Cells ( 0 ).Text +
", " + row.Cells ( 1 ).Text +
", " + row.Cells ( 2 ).Text
Next row
End Sub |
|
C# |
VB |
GridView Members GridViewRow RowIndex RowType