DataItem Property

DataListItem.DataItem Property

Gets or sets a data item associated with the DataListItem object in the DataList control.

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

public virtual Object DataItem { get; set; }

Property Value

Type: System.Object
An System.Object that represents a data item in the DataList control.

Use the DataItem property to specify or determine the properties of a data item associated with the DataListItem object in the DataList control.


This property only applies to data items in the DataList control. The ItemType property of the DataListItem object must be set to one of the ListItemType enumeration values.

The following example demonstrates how to use the DataItem property to display the contents of the data items 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 Forms Page Code Model.

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

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

      ICollection CreateDataSource() 

         // Create sample data for the DataList control.
         DataTable dt = new DataTable();
         DataRow dr;

         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(String)));
         dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));

         // Populate the table with sample values.
         for (int i = 0; i < 9; i++) 
            dr = dt.NewRow();

            dr[0] = i;
            dr[1] = "Description for item " + i.ToString();
            dr[2] = 1.23 * (i + 1);


         DataView dv = new DataView(dt);
         return dv;


      void Page_Load(Object sender, EventArgs e) 

         // Load sample data only once, when the page is first loaded.
         if (!IsPostBack) 
            ItemsList.DataSource = CreateDataSource();


      void Item_Created(Object sender, DataListItemEventArgs e)

         if (e.Item.ItemType == ListItemType.Item || 
             e.Item.ItemType == ListItemType.AlternatingItem)

            // Retrieve the Label control in the current DataListItem.
            Label PriceLabel = (Label)e.Item.FindControl("PriceLabel");

            // Retrieve the text of the CurrencyColumn from the DataListItem
            // and convert the value to a Double.
            Double Price = Convert.ToDouble(

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




<head runat="server">
    <title>DataList ItemCreated Example</title>

   <form id="form1" 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") %>

            <br />

            <asp:Label id="PriceLabel"





.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
© 2015 Microsoft