DataListItem Class

Represents an item in a DataList control.

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

Public Class DataListItem
	Inherits WebControl
	Implements IDataItemContainer, INamingContainer
Dim instance As DataListItem

public class DataListItem extends WebControl implements IDataItemContainer, INamingContainer
public class DataListItem extends WebControl implements IDataItemContainer, INamingContainer

A DataListItem represents an item in a DataList control, such as a heading section, a footer section, or a data item.

The data items in the DataList control are stored in a DataListItemCollection that can be accessed by using the Items property of the DataList control.

You can use a DataListItem to programmatically access the properties of an item in a DataList control.

The following example demonstrates how to use a DataListItem to display the contents of each data item in the DataList control.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
   <script runat="server">
      Function CreateDataSource() As ICollection 
         ' Create sample data for the DataList control.
         Dim dt As DataTable = New DataTable()
         Dim dr As DataRow
         ' Define the columns of the table.
         dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
         dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
         dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
         ' Populate the table with sample values.
         Dim i As Integer

         For i = 0 To 8 

            dr = dt.NewRow()
            dr(0) = i
            dr(1) = "Description for item " & i.ToString()
            dr(2) = 1.23 * (i + 1)

         Next i
         Dim dv As DataView = New DataView(dt)
         Return dv

      End Function
      Sub Page_Load(sender As Object, e As EventArgs) 

         ' Load sample data only once, when the page is first loaded.
         If Not IsPostBack Then
            ItemsList.DataSource = CreateDataSource()
         End If

      End Sub

      Sub Item_Created(sender As Object, e As DataListItemEventArgs)

         If e.Item.ItemType = ListItemType.Item Or _
             e.Item.ItemType = ListItemType.AlternatingItem Then

            ' Retrieve the Label control in the current DataListItem.
            Dim PriceLabel As Label = _
                CType(e.Item.FindControl("PriceLabel"), Label)

            ' Retrieve the text of the CurrencyColumn from the DataListItem
            ' and convert the value to a Double.
            Dim Price As Double = Convert.ToDouble( _
                (CType(e.Item.DataItem, DataRowView)).Row.ItemArray(2).ToString())

            ' Format the value as currency and redisplay it in the DataList.
            PriceLabel.Text = Price.ToString("c")

         End If

      End Sub
   <form runat=server>

      <h3>DataList ItemCreated Example</h3>
      <asp:DataList id="ItemsList"

         <HeaderStyle BackColor="#aaaadd">

         <AlternatingItemStyle BackColor="Gainsboro">


            List of items


            Description: <br>
            <%# DataBinder.Eval(Container.DataItem, "StringValue") %>


            <asp:Label id="PriceLabel"


  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand. Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand. Permission value: Minimal.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0