asp.net.ph

DataGrid.Items Property

System.Web.UI.WebControls Namespace   DataGrid Class


Returns the collection of DataGridItem objects in a DataGrid.

Syntax


Script [ DataGridItemCollection variable = ] DataGrid.Items

Property Value


variable Returns a DataGridItemCollection that represents the items within the list.

The property is read only with no default value.

Remarks

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.

Example

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;
   }
}
  C# VB

 Show me 

See Also

DataGrid Members   DataGridItem   ItemIndex   ItemType Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph