System.Web.UI.WebControls Namespace DataListItem Class
Returns the index of an item in a DataList control.
Script |
[ integer variable = ] DataListItem.ItemIndex |
variable |
Integer specifying the ordinal position of the DataListItem within the DataList control. |
The property is read only with no default value.
Use the ItemIndex property to determine the index number of a DataListItem from the Items collection of a DataList control.
NOTE: This property only applies to data items in the DataList control. The ItemType property must be set to ListItemType.Item, ListItemType.AlternatingItem, ListItemType.SelectedItem, or ListItemType.EditItem.
The following example demonstrates how to use the ItemIndex property to determine the position of an item in a DataList control. The type of each item is displayed along with the item index.
foreach ( DataListItem item in myDataList.Items ) {
msg.Text += "<br>" + item.ItemIndex + " " + item.ItemType;
}
dim item as DataListItem
for each item in myDataList.Items
msg.Text &= "<br>" & item.ItemIndex & " " & item.ItemType
next |
|
C# |
VB |
Show me
Below are links to further code examples that demonstrate use of the ItemIndex property in practical ASP.NET applications.
DataListItem Members ItemType