ObjectList Class

Enables you to specify multiple fields for display, per item in an object list.

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

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

Much of the behavior of the ObjectList, including support for templated rendering through device template sets and internal pagination, is similar to the behavior of the List. For more information, see the Introduction to the ObjectList Control or the Pagination documentation.

The following code example demonstrates how to create an array of a user-defined class and then bind it to an ObjectList object when the page loads. It also shows how the list and details views display the commands. For this example, there is also a button that displays a form with a list of all the fields using the AllFields property.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Page Code Model.

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

<script runat="server">
    int bakeryCount = 0, dairyCount = 0, produceCount = 0;

    public void Page_Load(Object o, EventArgs e)
        if (!IsPostBack)
        {   // Create an array and bind it to the list
            ArrayList arr = new ArrayList();
            arr.Add (new GroceryItem 
                ("Bakery", "Rolls", "On Sale"));
            arr.Add (new GroceryItem 
                ("Dairy", "Eggnog", "Half price"));
            arr.Add (new GroceryItem 
                ("Produce", "Apples", 
                "A dollar a bushel"));
            arr.Add (new GroceryItem 
                ("Bakery", "Bread", "On Sale"));

            List1.DataSource = arr;
            List1.DataBind ();

            // To show only one field on opening page,
            // comment the next line
            List1.TableFields = "Item;Department";
            List1.LabelField = "Department";

            // Display a report after items are databound
            string txt = "Number of items by Department<br>Produce: {0}<br />" +
                "Dairy: {1}<br />Bakery: {2}";
            TextView2.Text = String.Format(txt, produceCount, dairyCount, bakeryCount);

    // Command event for buttons
    public void List1_Click(Object sender, 
        ObjectListCommandEventArgs e)
        if (e.CommandName == "Reserve")
           ActiveForm = Form2;
        else if (e.CommandName == "Buy")
           ActiveForm = Form3;
           ActiveForm = Form4;

    // Count items in each department
    private void List1_ItemDataBind(object sender, ObjectListDataBindEventArgs e)
        switch (((GroceryItem)e.DataItem).Department)
            case "Bakery":
            case "Dairy":
            case "Produce":

    private void AllFields_Click(object sender, EventArgs e)
        ActiveForm = Form5;
        string spec = "{0}: {1}<br/>";
        IObjectListFieldCollection flds = List1.AllFields;
        for (int i = 0; i < flds.Count; i++)
            TextView1.Text += 
                String.Format(spec, (i + 1), flds[i].Title);

    // Structure for ArrayList records
    private class GroceryItem
    {   // A private class for the Grocery List
        private String _department, _item, _status;
        public GroceryItem(string department,
            string item, string status)
            _department = department;
            _item = item;
            _status = status;
        public String Department
        { get { return _department; } }
        public String Item
        { get { return _item; } }
        public String Status
        { get { return _status; } }

<html xmlns="http://www.w3.org/1999/xhtml" >
    <mobile:Form id="Form1" runat="server" BackColor="LightBlue">
        <mobile:ObjectList id="List1" runat="server" 
            OnItemCommand="List1_Click" OnItemDataBind="List1_ItemDataBind">
            <DeviceSpecific ID="DeviceSpecific1" Runat="server">
                <!-- See Web.config for filters -->
                <Choice Filter="isWML11" CommandStyle-Font-Bold="NotSet" />
                <Choice CommandStyle-Font-Bold="true" 
                    CommandStyle-Font-Name="Arial" />
            <Command Name="Reserve" Text="Reserve" />
            <Command Name="Buy" Text="Buy" />
        <mobile:Command ID="AllFieldsCmd" Runat="server" 
            List All Fields</mobile:Command>
        <mobile:TextView ID="TextView2" Runat="server" />
    <mobile:Form id="Form2" runat="server" BackColor="LightBlue">
        <mobile:Label id="ResLabel" runat="server"
            text="Sale item reservation system coming soon!" />
        <mobile:Link id="ResLink" NavigateURL="#Form1" 
            runat="server" text="Return" />
    <mobile:Form id="Form3" runat="server" BackColor="LightBlue">
        <mobile:Label id="BuyLabel" runat="server"
            Text="Online purchasing system coming soon!" />
        <mobile:Link ID="BuyLink" NavigateURL="#Form1" 
            Runat="server" text="Return" />
    <mobile:Form id="Form4" Runat="server" BackColor="LightBlue">
        <mobile:Label ID="DefLabel" Runat="server" 
             Text="Detailed item descriptions will be here soon!"/>
        <mobile:Link ID="DefLink" NavigateURL="#Form1" 
            Runat="server" Text="Return" />
    <mobile:Form ID="Form5" Runat="server">
        <mobile:Label Runat="server">
            List of AllFields:</mobile:Label>
        <mobile:TextView ID="TextView1" Runat="server" />
        <mobile:Link Runat="server" NavigateUrl="#Form1" 

This is a sample Web.config file with several device specific filters.

    <compilation debug="true" />
    <authentication mode="Windows" />
    <customErrors mode="Off" />
    <httpRuntime useFullyQualifiedRedirectUrl="true" />
    <mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData" />

      <!-- Only a few filters are provided here -->
      <filter name="isJPhone" compare="Type" argument="J-Phone" />
      <filter name="isHTML32" compare="PreferredRenderingType" argument="html32" />
      <filter name="isWML11" compare="PreferredRenderingType" argument="wml11" />


  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.

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