ListViewItemType Enumeration
Collapse the table of content
Expand the table of content

ListViewItemType Enumeration


Specifies the function of an item in the ListView control.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public enum ListViewItemType

Member nameDescription

A data item in the ListView control.


An empty item in the ListView control. The empty item is displayed when the ListView control has no records to display, or when a group in the ListView control has no more records to display.


An insert item in the ListView control.

The ListViewItemType enumeration identifies the function of items in a ListView control. You can use the ListViewItemType enumeration to identify the type of a ListViewItem object.

The following example shows how to use the ListViewItemType enumeration to check the type of a ListViewItem object.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

    // <Snippet2>
    protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
        Label EmailAddressLabel;
        if (e.Item.ItemType == ListViewItemType.DataItem)
            // Display the e-mail address in italics.
            EmailAddressLabel = (Label)e.Item.FindControl("EmailAddressLabel");
            EmailAddressLabel.Font.Italic = true;

            System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
            string currentEmailAddress = rowView["EmailAddress"].ToString();
            if (currentEmailAddress == "")
                EmailAddressLabel.Font.Bold = true;
    // </Snippet2>

<html xmlns="">
<head id="Head1" runat="server">
    <title>ListView ItemDataBound Example</title>
<body style="font: 10pt Trebuchet MS">
    <form id="form1" runat="server">
        ListView ItemDataBound Example</h3>
    <asp:ListView ID="ContactsListView" DataSourceID="ContactsDataSource" ConvertEmptyStringToNull="true"
        OnItemDataBound="ContactsListView_ItemDataBound" runat="server">
            <table cellpadding="2" width="680px" border="0">
                <tr style="background-color: #ADD8E6" runat="server">
                    <th runat="server">
                        First Name
                    <th runat="server">
                        Last Name
                    <th runat="server">
                        E-mail Address
                <tr runat="server" id="itemPlaceholder" />
            <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
                    <asp:NumericPagerField ButtonCount="10" />
            <tr style="background-color: #CAEEFF" runat="server">
                    <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
                    <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
                    <asp:Label ID="EmailAddressLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
    <!-- This example uses Microsoft SQL Server and connects      -->
    <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
    <!-- expression to retrieve the connection string value       -->
    <!-- from the Web.config file.                                -->
    <asp:SqlDataSource ID="ContactsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
        SelectCommand="SELECT FirstName, LastName, EmailAddress FROM SalesLT.Customer">

.NET Framework
Available since 3.5
Return to top
© 2015 Microsoft