Export (0) Print
Expand All
Expand Minimize

ListView.Items Property

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

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

'Declaration
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property Items As IList(Of ListViewDataItem)

Property Value

Type: System.Collections.Generic.IList(Of ListViewDataItem)
An object that contains all the data items of the current page of data in a ListView control.

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.

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.

Sub ProductsListView_ItemEditing(ByVal sender As Object, ByVal e As ListViewEditEventArgs)
  Dim item As ListViewItem = ProductsListView.Items(e.NewEditIndex)
  Dim dateLabel As Label = CType(item.FindControl("DiscontinuedDateLabel"), Label)

  If String.IsNullOrEmpty(dateLabel.Text) Then _
    Return

  'Verify if the item is discontinued.
  Dim discontinuedDate As DateTime = DateTime.Parse(dateLabel.Text)
  If discontinuedDate < DateTime.Now Then
    Message.Text = "You cannot edit a discontinued item."
    e.Cancel = True
    ProductsListView.SelectedIndex = -1
  End If
End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5
Show:
© 2015 Microsoft