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 値のいずれか 1 つ。

次の例では、 プロパティを 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 表示するレコードがない場合に表示されます。

通常、このプロパティを使用して、操作を実行する前にアイテムの種類を確認します。

適用対象

こちらもご覧ください