Classe ObjectList

Consente di specificare più campi da visualizzare per ciascun elemento di un elenco di oggetti.

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

Osservazioni

Nella sua quasi totalità il comportamento del controllo ObjectList, incluso il supporto per il rendering basato su modelli realizzato mediante insiemi di modelli di dispositivo e mediante l'impaginazione interna, è simile al comportamento della classe List. Per ulteriori informazioni, vedere Insiemi di modelli e controlli basati su modelli o la documentazione relativa all'impaginazione.

Esempio

In questo esempio viene mostrato come creare una matrice di una classe definita dall'utente e associarla a un oggetto ObjectList al momento del caricamento della pagina.

<%@ 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 GroceryItem
   private _department, _item, _status As String

   Public Sub New( department As String, item As String, status As String)
      _department = department
      _item = item
      _status = status
   End Sub

   Public ReadOnly Property Department as String
      Get
         Return _department
      End Get
   End Property
   Public ReadOnly Property Item as String
      Get
         Return _item
      End Get
   End Property
   Public ReadOnly Property Status as String
      Get
         Return _status
      End Get
   End Property
End Class

Public Sub Page_Load(o As Object, e As EventArgs)
   If Not IsPostBack Then
      Dim arr As New ArrayList()
      arr.Add (New GroceryItem ("Bakery", "French Rolls", "On Sale"))
      arr.Add (New GroceryItem ("Dairy", "Eggnog", "Half price"))
      arr.Add (New GroceryItem ("Produce", "Apples", "A dollar a bushel"))
      List1.DataSource = arr
      List1.DataBind
   End If
End Sub

Public Sub List1_Click(sender As Object, e As ObjectListCommandEventArgs)
   If e.CommandName = "Reserve" Then
      ActiveForm = Form2
   ElseIf e.CommandName = "Buy"
      ActiveForm = Form3
   Else
      ActiveForm = Form4
   End If
End Sub

</script>

<mobile:Form id="Form1" runat="server" BackColor="LightBlue">
   <mobile:ObjectList id="List1" runat="server"
         LabelField="item"
         OnItemCommand="List1_Click">
      <Command Name="Reserve" Text="Reserve"/>
      <Command Name="Buy" Text="Buy"/>
   </mobile:ObjectList>
</mobile:Form>

<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>

<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>

<mobile:Form id="Form4" runat="server" BackColor="LightBlue">
   <mobile:Label id="DefLabel" runat="server"
        text="Detailed descriptions of the items will be here soon!" />
   <mobile:Link id="DefLink" NavigateURL="#Form1" runat="server" text="Return" />
</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 GroceryItem
{
   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; } }
}

public void Page_Load(Object o, EventArgs e)
{
   if (!IsPostBack)
   {
      ArrayList arr = new ArrayList();
      arr.Add (new GroceryItem ("Bakery", "French Rolls", "On Sale"));
      arr.Add (new GroceryItem ("Dairy", "Eggnog", "Half price"));
      arr.Add (new GroceryItem ("Produce", "Apples", "A dollar a bushel"));
      List1.DataSource = arr;
      List1.DataBind ();
   }
}

public void List1_Click(Object sender, ObjectListCommandEventArgs e)
{
   if (e.CommandName == "Reserve")
   {
      ActiveForm = Form2;
   }
   else if (e.CommandName == "Buy")
   {
      ActiveForm = Form3;
   }
   else
   {
      ActiveForm = Form4;
   }
}

</script>

<mobile:Form id="Form1" runat="server" BackColor="LightBlue">
   <mobile:ObjectList id="List1" runat="server"
         LabelField="item"
         OnItemCommand="List1_Click">
      <Command Name="Reserve" Text="Reserve"/>
      <Command Name="Buy" Text="Buy"/>
   </mobile:ObjectList>
</mobile:Form>

<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>

<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>

<mobile:Form id="Form4" runat="server" BackColor="LightBlue">
   <mobile:Label id="DefLabel" runat="server"
        text="Detailed descriptions of the items will be here soon!" />
   <mobile:Link id="DefLink" NavigateURL="#Form1" runat="server" text="Return" />
</mobile:Form>

Requisiti

Spazio dei nomi: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

Vedere anche

Controllo ObjectList | Accesso ai dati