ObjectList Class
Enables you to specify multiple fields for display, per item in an object list.
Assembly: System.Web.Mobile (in System.Web.Mobile.dll)
'Declaration <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Class ObjectList _ Inherits PagedControl _ Implements INamingContainer, ITemplateable, IPostBackEventHandler 'Usage Dim instance As ObjectList
<mobile:ObjectList />
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.
Note: |
|---|
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="VB" Inherits="System.Web.UI.MobileControls.MobilePage" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <script runat="server"> Dim bakeryCount, dairyCount, produceCount As Integer Private Sub Page_Load(ByVal o As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Create an array and bind it to the list Dim arr As 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 Const txt As String = "Number of items by Department<br>Produce: " + _ "{0}<br />Dairy: {1}<br />Bakery: {2}" TextView2.Text = String.Format(txt, produceCount, dairyCount, bakeryCount) End If End Sub ' Command event for buttons Private Sub List1_Click(ByVal sender As Object, _ ByVal e As ObjectListCommandEventArgs) If e.CommandName = "Reserve" Then ActiveForm = Form2 ElseIf e.CommandName = "Buy" Then ActiveForm = Form3 Else ActiveForm = Form4 End If End Sub ' Count items in each department Private Sub List1_ItemDataBind(ByVal sender As Object, ByVal e As ObjectListDataBindEventArgs) Select Case CType(e.DataItem, GroceryItem).Department Case "Bakery" bakeryCount += 1 Case "Dairy" dairyCount += 1 Case "Produce" produceCount += 1 End Select End Sub Private Sub AllFields_Click(ByVal sender As Object, ByVal e As EventArgs) ActiveForm = Form5 Dim spec As String = "{0}: {1}<br/>" Dim flds As IObjectListFieldCollection = List1.AllFields Dim i As Integer For i = 0 To flds.Count - 1 TextView1.Text += _ String.Format(spec, (i + 1), flds(i).Title) Next End Sub ' Structure for ArrayList records Private Class GroceryItem ' A private class for the Grocery List Private _department, _item, _status As String Public Sub New(ByVal department As String, _ ByVal item As String, ByVal 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 </script> <html xmlns="http://www.w3.org/1999/xhtml" > <body> <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" /> </DeviceSpecific> <Command Name="Reserve" Text="Reserve" /> <Command Name="Buy" Text="Buy" /> </mobile:ObjectList> <mobile:Command ID="AllFieldsCmd" Runat="server" OnClick="AllFields_Click"> List All Fields</mobile:Command> <mobile:TextView ID="TextView2" Runat="server" /> </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 item descriptions will be here soon!"/> <mobile:Link ID="DefLink" NavigateURL="#Form1" Runat="server" Text="Return" /> </mobile:Form> <mobile:Form ID="Form5" Runat="server"> <mobile:Label ID="Label1" Runat="server"> List of AllFields:</mobile:Label> <mobile:TextView ID="TextView1" Runat="server" /> <mobile:Link ID="Link1" Runat="server" NavigateUrl="#Form1" Text="Return"></mobile:Link> </mobile:Form> </body> </html>
This is a sample Web.config file with several device specific filters.
<configuration>
<system.web>
<compilation debug="true" />
<authentication mode="Windows" />
<customErrors mode="Off" />
<httpRuntime useFullyQualifiedRedirectUrl="true" />
<mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData" />
<deviceFilters>
<!-- 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" />
</deviceFilters>
</system.web>
</configuration>
- 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.
System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.PagedControl
System.Web.UI.MobileControls.ObjectList
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: