ListViewItem.ItemType 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 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 群組沒有要顯示任何記錄時,就會顯示空白專案。 |
您通常會使用這個屬性來判斷項目的類型,再執行作業。