System.Web.UI.WebControls Namespace DataGrid Class
Returns the collection of DataGridItem objects in a DataGrid.
Script |
[ DataGridItemCollection variable = ] DataGrid.Items |
The property is read only with no default value.
The Items collection provides a way to programmatically obtain information about each data-bound item in a DataGrid control.
When a DataSource is bound to a DataGrid, the Items collection is populated with one DataGridItem object for each record ( or row of data ) in the data source.
The Items collection is then referenced at run time by the data-bound controls defined in the ItemTemplate and AlternatingItemTemplate, to render each item in the collection.
NOTE: Only items bound to the data source are contained in the Items collection. The header, footer, and separator items are not included.
The Items collection does not provide any methods to add or remove items to the collection. However, you can control the contents of an item by providing a handler for the ItemCreated event.
The following example show how to programmatically access the Items collection to retrieve and display the Text of the DataBoundLiteralControl associated with each item in a DataGrid control.
void getItems ( Object src, EventArgs e ) {
foreach ( DataGridItem item in myGrid.Items ) {
message.Text += "<br>" + item.Cells [ 0 ].Text +
" " + item.Cells [ 1 ].Text +
" " + item.Cells [ 2 ].Text;
}
}
Sub getItems ( src As Object, e As EventArgs )
Dim item As DataGridItem
For Each item In myGrid.Items
message.Text += "<br>" + item.Cells ( 0 ).Text +
" " + item.Cells ( 1 ).Text +
" " + item.Cells ( 2 ).Text
Next item
End Sub |
|
C# |
VB |
Show me
DataGrid Members DataGridItem ItemIndex ItemType