List Controls
Many day-to-day tasks involve the listing of data in a Web page. In general,
this data will be drawn from a data store of some type, perhaps a relational
database. The aim of the ASP+ List Controls is to
make building these kinds of pages easier. This involves encapsulating the functionality
required within a single control or set of controls, saving development time
and making the task easier.
The server-side ASP+ controls that generate the user interface can also manage
tasks such as paging the list, sorting the contents, filtering the list, and
selecting individual items. Finally, they can use the new server-side data binding
features in ASP+ to automatically populate the lists with data. The three standard
controls that are used to create lists are the Repeater,
DataList, and DataGrid controls.
The Repeater control is the simplest, and
is used simply to render the output a repeated number of times. The developer
defines templates that are used to apply styling information to the header,
item,
footer
and separator
parts of the output that is created by the control. To create a table, for example,
the header
and footer
information is used (as you would expect) for the header and footer of the table
(the <thead>
and <tfoot>
parts in HTML terms). The item template content is applied to
every row of the table that is generated from the repeated values – probably
the records from a data store of some type. There is also the facility to use
an alternatingItem
template to apply different styles to alternate rows. The separator
information defines the HTML output that will be generated after each row and
before the next one.
The DataList control differs from the Repeater
control in that it provides some intrinsic formatting of the repeated data as
well as accepting the same kinds of template values as the Repeater
control. The DataList control renders additional HTML
(outside of that defined in its templates) to better control the layout and
format of the rendered list, providing features such as vertical/horizontal
flow and style support. However, unlike the Repeater control, it can also be used
to edit the values in the elements on demand, and detect changes made by the
user.
The richest of the list controls is the DataGrid
control. The output is an HTML table, and the developer can define templates
that are used to apply styling information to the various parts of the table.
As well as being able to edit the values in the table, the user can also sort
and filter the contents, and the appearance is similar to that of using a spreadsheet.
However, as the output from the control is simply HTML, it will work in all
the popular browsers.
There are two other more specialized types of list control included with ASP+.
These are the RadioButtonList and
CheckboxList
controls. In effect, they simply render on the client a list of HTML radio button
or checkbox elements, with captions applied using span elements. However, you
can easily specify the layout, i.e. if the items should appear listed horizontally
across the page or vertically down it, or within an HTML table. You can also
control the alignment of the text labels, and arrange for the list to automatically
post back the selected values.