Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

public class List : PagedControl, INamingContainer, ITemplateable, IPostBackEventHandler
public class List extends PagedControl implements INamingContainer, ITemplateable, 
	IPostBackEventHandler
public class List extends PagedControl implements INamingContainer, ITemplateable, 
	IPostBackEventHandler

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="VB" 
    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 Shared doneCount, schedCount, pendCount As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            ' Set the DataMembers of the List
            List1.DataValueField = "Status"
            List1.DataTextField = "TaskName"

            ' Create an ArrayList of task data
            Dim arr As ArrayList = 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 spec As String = "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
        End If
    End Sub

    Private Sub Status_DataBinding(ByVal sender As Object, _
        ByVal e As ListDataBindEventArgs)

        ' Increment initial counts
        Select Case e.ListItem.Value
            Case "done"
                doneCount += 1
            Case "scheduled"
                schedCount += 1
            Case "pending"
                pendCount += 1
        End Select
    End Sub

    Private Sub Status_ItemCommand(ByVal sender As Object, _
        ByVal e As ListCommandEventArgs)

        Const spec As String = "You now have {0} tasks done, {1} " & _
            "tasks scheduled, and {2} tasks pending."

        ' Move selection to next status toward 'done'
        Select Case e.ListItem.Value
            Case "scheduled"
                schedCount -= 1
                pendCount += 1
                e.ListItem.Value = "pending"
            Case "pending"
                pendCount -= 1
                doneCount += 1
                e.ListItem.Value = "done"
                
        End Select

        ' 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)
    End Sub

    ' Custom class for the ArrayList items
    Private Class Task
        Private _TaskName, _Status As String
        
        Public Sub New(ByVal TaskName As String, _
            ByVal Status As String)

            _TaskName = TaskName
            _Status = Status
        End Sub
        Public ReadOnly Property TaskName() As String
            Get
                Return _TaskName
            End Get
        End Property
        Public ReadOnly Property Status() As String
            Get
                Return _Status
            End Get
        End Property
    End Class
</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>

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 Millennium Edition, 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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft