Welcome!

Microsoft Cloud Authors: Janakiram MSV, Yeshim Deniz, David H Deans, Andreas Grabner, Stackify Blog

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

Leveraging the List Controls in the Mobile Internet Toolkit

Leveraging the List Controls in the Mobile Internet Toolkit

Microsoft's Mobile Internet Toolkit represents one of the best ways available today to create Web-based applications that target multiple kinds of mobile devices, including:

  • Pocket PCs
  • WAP phones
  • Palm OS PDAs
  • i-Mode phones
The best thing about this technology, however, is that it doesn't require you to create multiple applications in order to target all of these. Instead, it provides you with a single, abstract set of server-side components with which to create a single .NET Web application that can adapt to any of these devices.

Some of the most powerful, yet least understood, of all the components in the Mobile Internet Toolkit are the various "list" objects. Of these, the first and simplest is simply known as the List control. A slightly more complex form of this control is the SelectionList. The absolute pinnacle of both power and difficulty-of-use, however, is the ObjectList control. In this article, I will give you a brief overview of the proper use of all three of these components.

The List List
As I mentioned above, the List control is the simplest of all the list components. In order to see it in action, simply drag it from the control palette onto any blank Form inside of any Mobile Web Page.

If you already know all of the items that you would like to have listed within this component, then you can set them all to this point using the Visual Studio Properties window. Within this window, there is an Items property. If you click this property, you will see a dialog like the one in Figure 1.

To add items to the list using this interface, simply click the "Create New Item" button. Next, fill in the "Item Text" field, then the corresponding "Item Value" field. The difference between these two values is simple: the values in "Item Text" will actually be displayed to users of your Web application, whereas the values in "Item Value" are what will actually be sent to your code when one of these items is selected.

To see an example of this, enter the names of several different Web sites as the "Text" values in your List control. For each of these Web sites, enter their URL as their "Value." For example, you might enter the Text of "SYS-CON Media homepage" and the Value of http://www.sys-con.com.

Before running your application, make sure that you have also set the List's ItemsAsLinks property to true. Now when you run your application you will see that all of the Text properties you entered are displayed on the Web page as hyperlinks. If you follow any of these hyperlinks, however, you will be taken to the URL specified in the associated Value property!

Rendering its Items as hyperlinks is the greatest degree of interactivity supported by the List control. It is intended principally for displaying output in an ordered fashion to a remote browser. There is, therefore, no way for the control to communicate back to your application once it has been rendered on the remote browser.

The SelectionList List
For situations in which a greater degree of interactivity is required or desired, the SelectionList is one of just two options provided to you by the base Mobile Internet Toolkit distribution. The other option, as we will see momentarily, is the ObjectList control. The SelectionList is not quite as powerful as the ObjectList, but it is much easier to use.

To see the SelectionList in action, first delete your existing List component, then drag a SelectionList from the palette and drop it onto the place where your List used to be. Notice that there is an Items collection for this list component just like there was for the first List control. Go ahead and add a few Text/Value pairs.

Notice that there is one feature on this dialog that was not on the dialog for the standard List control - the checkbox labeled "Selected." It is there because, unlike on the standard List control, items on the SelectionList may or may not be selected at any given point in time. In its default format, you can check this checkbox for as many items as you like.

When you close the Items dialog, you will see that the SelectionList is now displaying the first selected item that you have entered. If you did not select any items, then it is simply displaying whatever the first item is that you entered. Scroll up to the SelectType property and try all of the various settings underneath this property (see Table 1).

In Table 1, the first column (left to right) gives you the name of the SelectType option, as shown in the Properties dialog. The second column tells you the maximum number of items that will be displayed on the screen at a single time. For two of these - the Listbox and the MultiSelectListBox - this number is controlled by the Rows property, which is also visible in the Properties dialog.

Exclusive versus nonexclusive selectivity will determine whether or not you can choose multiple items using a given SelectList control. If you want to do this, you must set the SelectType for your SelectList to either MultiSelectListBox or Checkbox, because none of the other SelectTypes support this.

At this point, you should go ahead and add a Label and a Command control to your Mobile Web Form so that it looks like Figure 2. Double-click the SelectionList and enter the code shown in Listing 1. The SelectedIndex property will tell you the index of the first item that is selected in any SelectionList. Our code uses this property as an index into the SelectionList's Items collection so we can retrieve the Value of the first selected item.

If you run your Mobile Web application project now, you will see that when you select an item, nothing happens. However, when you click the button, a round-trip to the server is triggered and the Label text is populated with the value of the first selected item. This raises two interesting questions. First, how can we retrieve the Values of all the items selected, rather than just the first one - in case we are using one of the two SelectTypes in which multiple items can be chosen? Second, how can we avoid having to click the command button in order to trigger a round-trip to the server?

One approach to solving the first problem is shown in Listing 2. This code iterates through all of the items in a given SelectionList, checking the Selected property of each one. If this property is true, then it knows that the item has been selected and it concatenates its value to the end of the Caption string. At the end of the code, the entire caption string is pasted into the Label control.

The ObjectList List
Unfortunately, resolving our second issue is quite a bit more complicated. In order to do this, we will need to upgrade to the ObjectList control - which is by far the most complicated of the List controls. For our efforts, however, we will also be rewarded with the greatest degree of flexibility.

To begin with, the only way to get items into an ObjectList is to bind the ObjectList with a data source. You can verify this for yourself by deleting the Label, Command, and SelectionList from your existing Mobile Web Form and dragging an ObjectList onto the Mobile Web Form to replace them. If you examine the Properties window for this control, you will see that there is no Items property - therefore, there is no way to add items through the Properties window.

The good news is that, unlike all of the other List controls, this control supports multiple fields. This means that if you want to list many pieces of information for each item, you should always choose the ObjectList control. For example, whereas with the List or SelectionList controls you could display only the names of all your employees, with the ObjectList, you could display their names, ages, salaries, and Social Security numbers all at once!

In order to bind the ObjectList to a data source, you must first have a data source. This should be something that is accessible via ADO.NET, the new technology for accessing data using .NET. Examples of data that can be accessed via ADO.NET include:

  • SQL Server
  • Oracle
  • OLE DB data sources
  • ODBC data sources
You'll notice that the last two items are, in themselves, capable of providing connectivity to an even wider array of data sources. This is because there are, in fact, ADO.NET Managed Providers for providing legacy support for both of these older technologies.

Once you have a data source, you need to tell the ObjectList how to connect to it and what data it should use from it. You can do this by manipulating the properties described in Table 2.

The last two rows in Table 2 are of particular interest because they tell us something about the functionality of the ObjectList, which is quite different from either of the previous lists. When an ObjectList is first displayed, it presents a simple list composed of a single field, just like any of the other lists. This is the field denoted by the LabelField property and should be a unique identifier for all of the items in your ObjectList. If you were displaying data about employees, for example, you might choose their names for this display, or their Social Security numbers.

In this display, all of the items are links. In an HTML or cHTML browser, this would usually mean that they were all hyperlinks. On a WAP phone, it would probably mean that they were all items in a menu. Regardless of the form factor, they would all generate round-trips to the server immediately upon selection - unlike either of the two previous lists.

Once the server received the selection, it would present a second view of the data that "punched down" onto additional data about the chosen record. The fields in this view would be pulled from the TableFields property.

In addition to being able to display multiple data fields, the ObjectList is also alone in its ability to accept "commands" associated with each data item. This is possible via the Commands collection of the control, the Properties dialog for which is illustrated in Figure 3.

To add commands, simply click the "Create New Command" button and then enter your desired command names and texts. At runtime, the texts for each of your commands will be displayed as selectable commands on the punch-down view for each item.

In order to react to each of the commands, however, you will have to write some custom code. Listing 3 shows a general example of the kind of code that you will have to write. By double-clicking the ObjectList, you can bring up the ItemCommand event handler and note that it is passed an ObjectListCommandEventArgs object. This object has a number of useful properties, but here we use the CommandName property to determine which of the commands has been selected. The exact action you will want to perform will depend entirely upon the exact nature of your application and commands.

Conclusion
I hope that you have found this discussion of the various Lists available in the Mobile Internet Toolkit useful. If you have any questions, you know where to find me - [email protected]!

More Stories By Derek Ferguson

Derek Ferguson, founding editor and editor-in-chief of .Net Developer's Journal, is a noted technology expert and former Microsoft MVP.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
There is huge complexity in implementing a successful digital business that requires efficient on-premise and cloud back-end infrastructure, IT and Internet of Things (IoT) data, analytics, Machine Learning, Artificial Intelligence (AI) and Digital Applications. In the data center alone, there are physical and virtual infrastructures, multiple operating systems, multiple applications and new and emerging business and technological paradigms such as cloud computing and XaaS. And then there are pe...
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
DevOps at Cloud Expo – being held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real r...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that Keisoku Research Consultant Co. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Keisoku Research Consultant, Co. offers research and consulting in a wide range of civil engineering-related fields from information construction to preservation of cultural properties. For more information, vi...
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...
Elon Musk is among the notable industry figures who worries about the power of AI to destroy rather than help society. Mark Zuckerberg, on the other hand, embraces all that is going on. AI is most powerful when deployed across the vast networks being built for Internets of Things in the manufacturing, transportation and logistics, retail, healthcare, government and other sectors. Is AI transforming IoT for the good or the bad? Do we need to worry about its potential destructive power? Or will we...
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.