共用方式為


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 價值。

範例

以下範例說明如何利用該 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 控制組中沒有更多可顯示的紀錄時,會顯示空項目。

通常你會利用這個特性來判斷物品的類型,然後再執行操作。

適用於

另請參閱