Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
ListViewItem Class
 ItemType Property
.NET Framework Class Library
ListViewItem..::.ItemType Property

Updated: November 2007

Gets the item type of the ListViewItem object.

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

Visual Basic (Declaration)
Public ReadOnly Property ItemType As ListViewItemType
Visual Basic (Usage)
Dim instance As ListViewItem
Dim value As ListViewItemType

value = instance.ItemType
C#
public ListViewItemType ItemType { get; }
Visual C++
public:
property ListViewItemType ItemType {
    ListViewItemType get ();
}
J#
/** @property */
public ListViewItemType get_ItemType()
JScript
public function get ItemType () : ListViewItemType

Use the ItemType property to determine the type of item that the ListViewItem object represents, as listed in the following table.

Item type

Description

DataItem

A data item in the ListView control.

InsertItem

An insert item in the ListView control.

EmptyItem

An empty item in the ListView control. The empty item is displayed when the ListView control does not have any records to display, or when a group in the ListView control does not have any more records to display.

You typically use this property to determine an item's type before you perform an operation.

The following example shows how to use the ItemType property to determine whether the item that is being created is a data item. If the item is a data item, the e-mail address is displayed in italic. This code example is part of a larger example provided for the ListViewItem class.

Visual Basic
Protected Sub ContactsListView_ItemCreated(ByVal sender As Object, ByVal e As ListViewItemEventArgs)

  ' Retrieve the current item.
  Dim item As ListViewItem = e.Item

  ' Verify if the item is a data item.
  If item.ItemType = ListViewItemType.DataItem Then

    ' Get the EmailAddressLabel Label control in the item.      
    Dim EmailAddressLabel As Label = CType(item.FindControl("EmailAddressLabel"), Label)

    ' Display the e-mail address in italics.
    EmailAddressLabel.Font.Italic = True

  End If

End Sub

C#
protected void ContactsListView_ItemCreated(object sender, ListViewItemEventArgs e)
{
  // Retrieve the current item.
  ListViewItem item = e.Item;

  // Verify if the item is a data item.
  if (item.ItemType == ListViewItemType.DataItem)
  {
    // Get the EmailAddressLabel Label control in the item.
    Label EmailAddressLabel = (Label)item.FindControl("EmailAddressLabel");

    // Display the e-mail address in italics.
    EmailAddressLabel.Font.Italic = true;
  }
}

Windows Vista, Windows XP SP2, 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.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker