Partager via


MobileListItemCollection, classe

Représente une collection d'objets MobileListItem et est utilisé pour contenir les éléments d'un contrôle List et d'un contrôle SelectionList.

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

Syntaxe

'Déclaration
Public Class MobileListItemCollection
    Inherits ArrayListCollectionBase
    Implements IStateManager
'Utilisation
Dim instance As MobileListItemCollection
public class MobileListItemCollection : ArrayListCollectionBase, IStateManager
public ref class MobileListItemCollection : public ArrayListCollectionBase, IStateManager
public class MobileListItemCollection extends ArrayListCollectionBase implements IStateManager
public class MobileListItemCollection extends ArrayListCollectionBase implements IStateManager

Notes

L'accès à la propriété Items d'un contrôle List ou à la propriété Items d'un contrôle SelectionList récupère un objet MobileListItemCollection. Vous pouvez ajouter ou supprimer des éléments de la collection au moment de l'exécution.

Un objet MobileListItemCollection hérite de l'interface ICollection.

Exemple

L'exemple de code suivant montre comment manipuler des éléments dans l'objet MobileListItem par le biais de la classe MobileListItemCollection. Le code utilise l'index de l'élément sélectionné dans la propriété SelectionList.Items.

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

<script runat="server">
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            Label1.Text = "Select an item"

            ' Create and fill an array list.
            Dim listValues As New ArrayList()
            listValues.Add("One")
            listValues.Add("Two")
            listValues.Add("Three")

            ' Bind the array to the list.
            SelList1.DataSource = listValues
            SelList1.DataBind()

            ' Set the SelectType.
            SelList1.SelectType = ListSelectType.Radio
        Else
            If (SelList1.SelectedIndex > -1) Then
                ' To show the selection, use the Selection property.
                Label1.Text = "Your selection is " & _
                    SelList1.Selection.Text

                ' Or, show the selection by using 
                ' the MobileListItemCollection class.
                ' Get the index of the selected item
                Dim idx As Integer = SelList1.SelectedIndex
                Label2.Text = "You have selected " & _
                    SelList1.Items(idx).Text

                ' Insert a copy of the selected item
                Dim mi As MobileListItem = SelList1.Selection
                Label3.Text = "The index of your selection is " & _
                    mi.Index.ToString()
                SelList1.Items.Insert(idx, _
                    New MobileListItem(mi.Text + " Copy"))
            Else
                Label1.Text = "No items selected"
            End If
        End If
    End Sub
</script>

<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <mobile:Label id="Label1" runat="server" 
            Text="Show a list" />
        <mobile:Label id="Label2" runat="server" />
        <mobile:Label id="Label3" runat="server" />
        <mobile:SelectionList runat="server" 
            id="SelList1" />
        <mobile:Command id="Command1" runat="server" 
            Text=" OK " />
    </mobile:form>
</body>
</html>
<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    public void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label1.Text = "Select an item";

            // Create and fill an array list.
            ArrayList listValues = new ArrayList();
            listValues.Add("One");
            listValues.Add("Two");
            listValues.Add("Three");

            // Bind the array to the list.
            SelList1.DataSource = listValues;
            SelList1.DataBind();

            // Set the SelectType.
            SelList1.SelectType =
                System.Web.UI.MobileControls.ListSelectType.Radio;
        }
        else
        {
            if (SelList1.SelectedIndex > -1)
            {
                // To show the selection, use the Selection property.
                Label1.Text = "Your selection is " +
                    SelList1.Selection;

                // Or, show the selection by using 
                // the MobileListItemCollection class.
                // Get the index of the selected item
                int idx = SelList1.SelectedIndex;
                Label2.Text = "You have selected " +
                    SelList1.Items[idx].Text;

                // Insert a copy of the selected item
                MobileListItem mi = SelList1.Selection;
                Label3.Text = "The index of your selection is " + 
                    mi.Index.ToString();
                SelList1.Items.Insert(idx, 
                    new MobileListItem(mi.Text + " Copy"));
            }
            else
            {
                Label1.Text = "No items selected";
            }
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <mobile:Label id="Label1" runat="server" 
            Text="Show a list" />
        <mobile:Label id="Label2" runat="server" />
        <mobile:Label id="Label3" runat="server" />
        <mobile:SelectionList runat="server" 
            id="SelList1" />
        <mobile:Command id="Command1" runat="server" 
            Text=" OK " />
    </mobile:form>
</body>
</html>

Sécurité .NET Framework

  • AspNetHostingPermission  pour opérer dans un environnement hébergé. Valeur de demande : LinkDemand ; valeur d'autorisation : Minimal
  • AspNetHostingPermission  pour opérer dans un environnement hébergé. Valeur de demande : InheritanceDemand ; valeur d'autorisation : Minimal

Hiérarchie d'héritage

System.Object
   System.Web.UI.MobileControls.ArrayListCollectionBase
    System.Web.UI.MobileControls.MobileListItemCollection

Sécurité des threads

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

Plates-formes

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

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

Informations de version

.NET Framework

Prise en charge dans : 2.0, 1.1

Voir aussi

Référence

Membres MobileListItemCollection
System.Web.UI.MobileControls, espace de noms
Clear

Autres ressources

Introduction au contrôle List
Introduction au contrôle SelectionList