ListViewItem.ItemType 屬性

定義

取得 ListViewItem 物件的項目型別。

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

屬性值

ListViewItemType

其中一個 ListViewItemType 值。

範例

下列範例示範如何使用 ItemType 屬性來判斷所建立的專案是否為數據項。 如果專案是資料項目,電子郵件地址會顯示在斜體中。 此程式碼範例是針對 類別提供的較大範例的 ListViewItem 一部分。

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

備註

ItemType使用 屬性來判斷物件所代表的專案 ListViewItem 類型,如下表所列。

項目類型 描述
DataItem ListView 控制項中的資料項目。
InsertItem ListView 控制項中的插入項目。
EmptyItem ListView 控制項中的空白項目。 當 ListView 控制項沒有要顯示的任何記錄,或控制項中的 ListView 群組沒有更多要顯示的記錄時,就會顯示空白專案。

您通常會使用這個屬性來判斷專案的類型,再執行作業。

適用於

另請參閱