Cette documentation est archivée et n’est pas conservée.

List, classe

Mise à jour : novembre 2007

Génère le rendu d'une liste d'éléments sous forme d'affichage statique ou de liste interactive.

Espace de noms :  System.Web.UI.MobileControls
Assembly :  System.Web.Mobile (dans System.Web.Mobile.dll)

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

Ce contrôle prend en charge le rendu basé sur des modèles en utilisant des ensembles de modèles de périphériques et la pagination interne. Pour plus d'informations, consultez Vue d'ensemble des filtres de périphérique ASP.NET et Pagination.

L'exemple de code suivant montre comment un tableau lie et remplit un List. Remarquez que vous pouvez définir par programme les propriétés DataTextField et DataValueField de l'objet List.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    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;
            List1.DataBind();

            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";
                break;
            case "pending":
                pendCount -= 1;
                doneCount += 1;
                e.ListItem.Value = "done";
                break;
        }

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

        // 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;
                break;
            case "scheduled":
                schedCount += 1;
                break;
            case "pending":
                pendCount += 1;
                break;
        }
    }

    // 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; }
        }
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <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:Label>
        <mobile:List runat="server" id="List1" 
            OnItemCommand="Status_ItemCommand" 
            OnItemDataBind="Status_DataBinding" />
        <mobile:Label runat="server" id="Label1" 
            ForeColor="green" Font-Italic="true" />
        <mobile:Label id="Label2" runat="server" />
    </mobile:form>
</body>
</html>


Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0, 1.1
Afficher: