Chapter 17. Using Server Data

The ASP.NET AJAX features introduced thus far all contribute to a considerable savings in development time and effort. Yet, there are more, very powerful features and functionality yet to come.

In this chapter, you’ll learn how to use ASP.NET AJAX to connect to databases and bind data from these sources to page elements. This functionality isn’t limited to simple, static controls like text fields, but lets you bind complex data as well. With ASP.NET AJAX, you can use tables and HTML lists to display data and, as with so many other features we’ve explored, you can create your own custom data source.

In Chapter 16, you were introduced to client control data binding. However, servers were not a part of this discussion. This chapter will expand upon what you learned about data binding, dealing with data from a server. You will write a web service that retrieves data from the data source and return it. You will then use the client ASP.NET AJAX controls and xml-script markup to display that data in HTML.

Using a ListView Control

The best way to display data in ASP.NET AJAX is using the ListView control (in xml-script, the <listView> element). This control can iterate through a list so that the user can view the result—hence, the name of the control.

Within a <listView> xml-script element, you can define two display templates:

<layoutTemplate>

To specify the layout and appearance of the data

<itemTemplate>

To specify the layout for each individual element (item) of ...

Get Programming ASP.NET AJAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.