Chapter 18. Using the Repeater Control


ASP.NET Developer's JumpStart
By Paul D. Sheriff, Ken Getz
Table of Contents
Part II.  Data Handling


  • Learn how list-bound controls work

  • Add templates to control the behavior of the Repeater control

  • Bind data to templates within the Repeater control

  • React to events of items in the Repeater control

ASP.NET provides three controls Repeater, DataList, and DataGrid that display data, either from ADO.NET or from any data source that supports the IEnumerable interface. Each of these controls provides a template-based display of the data, meaning that you separate the data binding from the display of the data. Each of these controls renders the contents of its data source according to the HTML tem plates you supply for the header, items, footer, and so on.

The basic concept behind all these controls is that you've provided some data source and, at the time the page framework renders the page, ASP.NET visits each row in the data source and uses templates you supply to fashion the HTML output for the page, one row at a time. It's obvious what the DataGrid control does you've seen it in action already. The DataList control can present data in any number of ways, using the templates you'll supply for each item. You can set properties of the DataList control that determine the layout of the data displayed on the page, such as the number of columns and whether you want to display rows down the page first or across the page first. The Repeater control gets its name because it can only do one thing: You provide it with a template for displaying items, and it repeatedly fills the template with data and displays that data on the page, from top to bottom, as it navigates through the input data source.

In addition, the DataGrid and DataList controls allow you to select, edit, and delete data as well as provide support for style and appearance properties. The Repeater control, however, has one basic purpose in life: It can display data, using HTML templates, in a flow layout. You can embed server controls within the Repeater so that you can react to navigation requests from within the Repeater control's data. Table 18.1 lists important features of the three different list-bound controls so that you can compare your needs against the available capabilities of the controls to decide which one to use.

Table 18.1. Each of the List-Bound Server Controls in ASP.NET Work Slightly Differently
Functionality Repeater DataList DataGrid
Templates Yes (required) Yes (Required) Within columns (optional)
Tabular layout No No Yes
Flow layout Yes Yes No
Columnar/newspaper-style layout No Yes No
Style/appearance properties No Yes Yes
Selection No Yes Yes
Editing No Yes Yes
Deleting No Yes Yes
Paging No No Yes
Sorting No No Yes

The previous chapters dealt with the DataGrid control, in some detail. In this chapter, you'll see how to create a simple Repeater control containing hyperlinks as well as how to create a tabular Repeater that reacts to events triggered as you click links within the control. In the next chapter, you'll try out the DataList control.


    ASP. NET Developer's JumpStart
    ASP.NET Developers JumpStart
    ISBN: 0672323575
    EAN: 2147483647
    Year: 2002
    Pages: 234 © 2008-2017.
    If you may any questions please contact us: