ListViewItem.ItemType Właściwość

Definicja

Pobiera typ ListViewItem elementu obiektu.

public:
 property System::Web::UI::WebControls::ListViewItemType ItemType { System::Web::UI::WebControls::ListViewItemType get(); };
public System.Web.UI.WebControls.ListViewItemType ItemType { get; }
member this.ItemType : System.Web.UI.WebControls.ListViewItemType
Public ReadOnly Property ItemType As ListViewItemType

Wartość właściwości

Jedna z ListViewItemType wartości.

Przykłady

W poniższym przykładzie pokazano, jak za pomocą ItemType właściwości określić, czy tworzony element jest elementem danych. Jeśli element jest elementem danych, adres e-mail jest wyświetlany kursywą. Ten przykład kodu jest częścią większego przykładu podanego ListViewItem dla klasy.

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 email address in italics.
    EmailAddressLabel.Font.Italic = true;
  }
}
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 email address in italics.
    EmailAddressLabel.Font.Italic = True
          
  End If

End Sub

Uwagi

Użyj właściwości , ItemType aby określić typ elementu, który ListViewItem reprezentuje obiekt, jak pokazano w poniższej tabeli.

Typ elementu Opis
DataItem Element danych w kontrolce ListView .
InsertItem Wstaw element w kontrolce ListView .
EmptyItem Pusty element w kontrolce ListView . Pusty element jest wyświetlany, gdy kontrolka ListView nie ma żadnych rekordów do wyświetlenia lub gdy grupa w kontrolce ListView nie ma więcej rekordów do wyświetlenia.

Zazwyczaj ta właściwość służy do określania typu elementu przed wykonaniem operacji.

Dotyczy

Zobacz też