List Class

Provides control capability to render a list of items as either a static display or an interactive list.

public class System.Web.UI.MobileControls.List : 
   System.Web.UI.MobileControls.IListControl,
   System.Web.UI.INamingContainer, 
   System.Web.UI.IPostBackEventHandler,
   System.Web.UI.MobileControls.ITemplateable, 
   System.Web.UI.MobileControls.PagedControl

Remarks

This control supports templated rendering by using device template sets and internal pagination. For more information, see the Template Sets and Templated Controls or the Pagination documentation.

Example

This 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 Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="VB" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script Language="vb" runat="server">
Public Class Task
   Private _TaskName, _Status As String
      
   Public Sub New (TaskName As String, 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

Public Sub Page_Load (sender As Object, e As EventArgs)
   If Not IsPostBack Then
      List1.DataValueField = "Status"
      List1.DataTextField = "TaskName"
      Dim arr As New ArrayList
      arr.Add (New Task ("Verify transactions", "done"))
      arr.Add (New Task ("Check balance sheet", "scheduled"))
      arr.Add (New Task ("Send report", "pending"))
      List1.DataSource = arr
      List1.DataBind
   End If
End Sub

Sub ShowStatus (sender As Object, e As ListCommandEventArgs)
   Label1.Text = e.ListItem.Text + " is " + e.ListItem.Value
End Sub
</script>

<mobile:Form runat="server" id="Form1" >
   <mobile:List runat="server" id="List1" 
      OnItemCommand="ShowStatus" />
   <mobile:Label runat="server" id="Label1" ForeColor=green 
      Font-Italic=true />
</mobile:Form>
[C#]
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="c#" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script Language="c#" runat="server">
class Task
{
   private String _TaskName, _Status;
      
   public Task(String TaskName, String Status) 
   { 
      _TaskName = TaskName; 
      _Status = Status;
   }   

   public String TaskName { get { return _TaskName; } }
   public String Status { get { return _Status; } }
}

public void Page_Load(Object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      List1.DataValueField = "Status";
      List1.DataTextField = "TaskName";
      ArrayList arr = new ArrayList();
      arr.Add (new Task ("Verify transactions", "done"));
      arr.Add (new Task ("Check balance sheet", "scheduled"));
      arr.Add (new Task ("Send report", "pending"));
      List1.DataSource = arr;
      List1.DataBind();
   }
}

void ShowStatus(Object sender, ListCommandEventArgs e)
{ 
   Label1.Text = e.ListItem.Text + " is " + e.ListItem.Value;
}
</script>

<mobile:Form runat="server" id="Form1" >
   <mobile:List runat="server" id="List1" 
      OnItemCommand="ShowStatus" />
   <mobile:Label runat="server" id="Label1" ForeColor=green 
      Font-Italic=true />
</mobile:Form>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

See Also

List Control | Accessing Data | Template Sets and Templated Controls | Pagination