This documentation is archived and is not being maintained.

List Class

Renders a list of items as either a static display or an interactive list.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class List : PagedControl, INamingContainer, ITemplateable, 
<mobile:List />

This control supports templated rendering by using device template sets and internal pagination. For more information, see ASP.NET Device Filtering Overview and Pagination.

The following code example demonstrates how an array binds and fills a List. Notice that you can programmatically set the DataTextField and DataValueField properties of the List object.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    // Persist across multiple postbacks. 
    private static int doneCount, schedCount, pendCount;

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            // Set the DataMembers of the List
            List1.DataValueField = "Status";
            List1.DataTextField = "TaskName";

            // Create an ArrayList of task data
            ArrayList arr = new ArrayList();
            arr.Add(new Task("Define transactions", "scheduled"));
            arr.Add(new Task("Verify transactions", "scheduled"));
            arr.Add(new Task("Check balance sheet", "scheduled"));
            arr.Add(new Task("Compile balance sheet", "scheduled"));
            arr.Add(new Task("Prepare report", "scheduled"));
            arr.Add(new Task("Send report", "scheduled"));

            // Bind the array to the list
            List1.DataSource = arr;

            const string spec = "Start: {0} tasks are done, {1} " +
               "tasks are scheduled, and {2} tasks are pending.";
            Label2.Text = String.Format(spec, doneCount, +
                schedCount, pendCount);

            List1.Decoration = ListDecoration.Bulleted;

    private void Status_ItemCommand(object sender, 
        ListCommandEventArgs e)
        const string spec = "You now have {0} " + 
            "tasks done, {1} tasks scheduled, and " +
            "{2} tasks pending.";

        // Move selection to next status toward 'done' 
        switch (e.ListItem.Value)
            case "scheduled":
                schedCount -= 1;
                pendCount += 1;
                e.ListItem.Value = "pending";
            case "pending":
                pendCount -= 1;
                doneCount += 1;
                e.ListItem.Value = "done";

        // Show the status of the current task
        Label1.Text = e.ListItem.Text + " is " +

        // Show current selection counts
        Label2.Text = String.Format(spec, doneCount, 
            schedCount, pendCount);

    private void Status_DataBinding(object sender, 
        ListDataBindEventArgs e)
        // Increment initial counts 
        switch (e.ListItem.Value)
            case "done":
                doneCount += 1;
            case "scheduled":
                schedCount += 1;
            case "pending":
                pendCount += 1;

    // Custom class for the ArrayList items 
    private class Task
        private string _TaskName;
        private string _Status;

        public Task(string taskName, string status)
            _TaskName = taskName;
            _Status = status;

        public string TaskName
            get { return _TaskName; }

        public string Status
            get { return _Status; }

<html xmlns="" >
    <mobile:form id="form1" runat="server">
        <mobile:Label ID="Label3" Runat="server">
            Click a task to change its status from 
            scheduled to pending or from pending to done:
        <mobile:List runat="server" id="List1" 
            OnItemDataBind="Status_DataBinding" />
        <mobile:Label runat="server" id="Label1" 
            ForeColor="green" Font-Italic="true" />
        <mobile:Label id="Label2" runat="server" />

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1