ListView.Items Property

Definition

Gets a collection of ListViewDataItem objects that represent the data items of the current page of data in a ListView control.

C#
[System.ComponentModel.Browsable(false)]
public virtual System.Collections.Generic.IList<System.Web.UI.WebControls.ListViewDataItem> Items { get; }

Property Value

An object that contains all the data items of the current page of data in a ListView control.

Attributes

Examples

The following example shows how to use the Items collection to access the item that is being edited in a ListView control. This code example is part of a larger example provided for the ItemEditing event.

C#
void ProductsListView_ItemEditing(Object sender, ListViewEditEventArgs e)
{
  ListViewItem item = ProductsListView.Items[e.NewEditIndex];
  Label dateLabel = (Label)item.FindControl("DiscontinuedDateLabel");
  
  if (String.IsNullOrEmpty(dateLabel.Text))
    return;
  
  //Verify if the item is discontinued.
  DateTime discontinuedDate = DateTime.Parse(dateLabel.Text);
  if (discontinuedDate < DateTime.Now)
  {
    Message.Text = "You cannot edit a discontinued item.";
    e.Cancel = true;
    ProductsListView.SelectedIndex = -1;
  }       
}

Remarks

The Items property is used to store the data items in a ListView control. The ListView control automatically populates the Items collection by creating one ListViewDataItem object for each record in the current page of data in the data source. It then adds each object to the collection. This property is usually used to access a specific item in the control or to iterate though the complete collection of items.

Applies to

Produkt Verzie
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also