Microsoft KB Archive/311250

= INFO: Different View Modes of the ObjectList Control =

Article ID: 311250

Article Last Modified on 6/14/2002

-

APPLIES TO


 * Microsoft Mobile Internet Toolkit 1.0

-



This article was previously published under Q311250



SUMMARY
This article describes the view modes of the ObjectList control. Additionally, this article demonstrates how to use the ObjectList.ViewMode property to change the view mode of the control.



Views of the ObjectList Control
The ObjectList control supports the following view modes based on the client (HTML or WML device) that views the data:
 * List View (the default view)
 * HTML device: Each label field is displayed as a hyperlink. If the TableFields property is set, this view displays a table with a column for each value that is separated by a semicolon.
 * WML device: Each label field is displayed as a hyperlink.
 * Commands View
 * HTML device: This view displays the selected item, each field name and value, and the commands as hyperlinks.
 * WML device: This view displays only the commands of each item.
 * Details View
 * HTML device: This view displays the selected item, each field name and value, and the commands as hyperlinks.
 * WML device: This view displays the details of the command that is selected.

Code to Change the View Mode of the ObjectList Control
The code in this section demonstrates how to change the view mode of the ObjectList control programmatically.

This code contains two forms, Form1 and Form2. Form1 displays an ObjectList control in which the ViewMode property is set. Form2 displays a list of option buttons that allow you to select the view mode of the ObjectList control. After you select a view mode, you are returned to Form1, which displays the ObjectList control in the view mode that you selected.

NOTE: You must select an item before you change from one view to another. <%@ Register TagPrefix=&quot;mobile&quot; Namespace=&quot;System.Web.UI.MobileControls&quot; Assembly=&quot;System.Web.Mobile&quot; %> <%@ Page language=&quot;c#&quot; Inherits=&quot;System.Web.UI.MobileControls.MobilePage&quot; AutoEventWireup=&quot;true&quot; %>

          </mobile:SelectionList> <mobile:Command id=command1 OnClick=Change_View runat=&quot;server&quot; Text=&quot;Change View&quot;></mobile:Command> </mobile:Form>

void View_Changed(Object sender, EventArgs e) { ActiveForm = Form1; }

void Change_View(Object sender, EventArgs e) { switch(SelectionList1.SelectedIndex) {       case 0: {           ObjectList1.ViewMode = ObjectListViewMode.List; break; }

case 1: {           ObjectList1.ViewMode = ObjectListViewMode.Commands; break; }              case 2: {           ObjectList1.ViewMode = ObjectListViewMode.Details; break; }          }

ActiveForm = Form1; }

void Page_Load(Object sender, EventArgs e) { ObjectList1.ItemCommand += new ObjectListCommandEventHandler(CommandClicked); if(!IsPostBack) {          ObjectList1.DataSource = CreateData; ObjectList1.LabelField = &quot;FirstName&quot;; ObjectList1.DataMember = &quot;Age&quot;; ObjectListCommand objCommand;

objCommand = new ObjectListCommand; objCommand.Name = &quot;FirstName&quot;; objCommand.Text = &quot;First Name Details&quot;; ObjectList1.Commands.Add(objCommand); objCommand = new ObjectListCommand; objCommand.Name = &quot;LastName&quot;; objCommand.Text = &quot;Last Name Details&quot;; ObjectList1.Commands.Add(objCommand);

objCommand = new ObjectListCommand; objCommand.Name = &quot;Age&quot;; objCommand.Text = &quot;Age Details&quot;; ObjectList1.Commands.Add(objCommand); ObjectList1.DataBind; } }

void CommandClicked(Object Sender, ObjectListCommandEventArgs e) { ActiveForm = Form2; }

public ArrayList CreateData {   ArrayList arr = new ArrayList; arr.Add(new DataObject(&quot;Mary&quot;, &quot;Baker&quot;, &quot;53&quot;)); arr.Add(new DataObject(&quot;Juan&quot;, &quot;Cao&quot;, &quot;33&quot;)); arr.Add(new DataObject(&quot;Karen&quot;, &quot;Friske&quot;, &quot;32&quot;)); arr.Add(new DataObject(&quot;Mark&quot;, &quot;Lee&quot;, &quot;27&quot;));

return arr; }

public class DataObject {   private String _strFirstName; private String _strLastName; private String _strAge;

public DataObject(String strFirstName, String strLastName, String strAge) {       _strFirstName = strFirstName; _strLastName = strLastName; _strAge = strAge; }

public String FirstName {       get{return _strFirstName;} }

public String LastName {       get{return _strLastName;} }

public String Age {       get{return _strAge;} }

}//end class

Keywords: kbinfo kbwmldevice kbtemplate kbservercontrols kbhtmldevice kbchtmldevice KB311250

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.