asp.net.ph

DataList.Items Property

System.Web.UI.WebControls Namespace   DataList Class


Returns the collection of DataListItem objects in a DataList.

Syntax


Script [ DataListItemCollection variable = ] DataList.Items

Property Value


variable Returns a DataListItemCollection 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 DataList control.

When a DataSource is bound to a DataList, the Items collection is populated with one DataListItem 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 examples show how to programmatically access the Items collection of a DataList control.

The below example shows using the Items collection to determine and display the ItemIndex and ItemType of each DataListItem in the collection.

foreach ( DataListItem item in myDataList.Items ) {
   Response.Write ( item.ItemIndex + " " + item.ItemType + "<br>" );
}

 Show me 

The below example shows using the Items collection to retrieve and display the Text of the DataBoundLiteralControl associated with each item, which is accessed via the DataListItem.Controls property.

foreach ( DataListItem item in myDataList.Items ) {
   Response.Write ( ( ( DataBoundLiteralControl ) item.Controls [ 0 ] ).Text + 
      "<br>" );
}

 Show me 

See Also

DataList Members   DataListItem   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