| |||||
DataList.Items PropertySystem.Web.UI.WebControls Namespace DataList Class Returns the collection of DataListItem objects in a DataList. Syntax
Property Value
The property is read only with no default value. RemarksThe 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.
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. ExampleThe 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>" );
}
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>" );
}
See AlsoDataList Members DataListItem ItemIndex ItemType |
| ||||
Check out related books at Amazon
© 2000-2008 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 aspxtreme