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 组没有更多要显示的记录时,将显示空项。 |
在执行操作之前,通常使用此属性来确定项的类型。