.NET Framework Class Library
ListViewDataItem..::.DisplayIndex Property

Gets the position of the data item as displayed in the ListView control.

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

Visual Basic (Declaration)
Public Overridable ReadOnly Property DisplayIndex As Integer
Visual Basic (Usage)
Dim instance As ListViewDataItem
Dim value As Integer

value = instance.DisplayIndex
C#
public virtual int DisplayIndex { get; }
Visual C++
public:
virtual property int DisplayIndex {
    int get ();
}
JScript
public function get DisplayIndex () : int

Property Value

Type: System..::.Int32
The zero-based position of the data item as displayed in the ListView control.

Implements

IDataItemContainer..::.DisplayIndex
Remarks

The DisplayIndex property corresponds to the current position of the item as displayed by the ListView control. Each item's DisplayIndex value reflects the order in which they were added to the control in that particular page of data. You can use the DisplayIndex property to retrieve a ListViewDataItem object in the Items collection.

NoteNote:

This property applies only to data items. It does not apply to insert items or empty items.

Examples

The following example shows how to use the DisplayIndex property to retrieve the index of the item that is being edited. This code example is part of a larger example provided for the ListView..::.UpdateItem method.

Visual Basic
Protected Sub PreferredCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) 

  ' Gets the CheckBox object that fired the event.
  Dim chkBox As CheckBox = CType(sender, CheckBox)

  ' Gets the item that contains the CheckBox object. 
  Dim item As ListViewDataItem = CType(chkBox.Parent.Parent, ListViewDataItem)

  ' Update the database with the changes.
  VendorsListView.UpdateItem(item.DisplayIndex, False)    

End Sub
C#
protected void PreferredCheckBox_CheckedChanged(object sender, EventArgs e)
{
  // Gets the CheckBox object that fired the event.
  CheckBox chkBox = (CheckBox) sender;

  // Gets the item that contains the CheckBox object. 
  ListViewDataItem item = (ListViewDataItem) chkBox.Parent.Parent;

  // Update the database with the changes.
  VendorsListView.UpdateItem(item.DisplayIndex, false);
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Other Resources

Tags :


Page view tracker