Overview of Data Controls in ASP.NET 4.0
Part two of a five-part series of blogs

With the introduction of the ListView data control in ASP.NET 3.5, there are now 4 separate tools for displaying multiple rows of data in ASP.NET. Which one is best - GridView, Repeater, DataList or ListView?

  1. Data Controls in ASP.NET 4.0 - Multiple Rows
  2. Repeater Web Server Controls in ASP.NET (this blog)
  3. DataList Controls - ASP.NET data controls
  4. GridView Controls in ASP.NET
  5. ListView Controls - ASP.NET data controls

Posted by Andy Brown on 19 September 2011

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Repeater Web Server Controls in ASP.NET

An example of a Repeater control is shown below:

Example of a repeater

Example of a repeater

Here every other row appears in a different colour.

Source HTML for a Repeater

The source HTML for the repeater shown above is as follows (I haven't shown the data source here, but it's a simple SELECT statement):

Repeater HTML source code

The source code for the repeater above

Here is the HTML that this generates:

The HTML generated by this repeater

The HTML generated by this repeater

Thus a typical repeater has:

  • The <table> tag in the header section, together with a title row
  • One row in each item or alternating item template
  • The </table> end table tag in the footer section

Repeater Events

The Repeater control exposes the following events:

Repeater events

The Repeater control doesn't support many events (compare this to the GridView control shown later in this blog).


Conclusion and Recommendation

The Repeater control is good for one thing only - creating simple web pages of pure HTML.  If you're using ASP.NET to create websites where you can only use pure HTML, repeaters are for you!  Otherwise, we'd ignore them and use the much more powerful gridviews instead.

This blog has 0 threads Add post