BLOGS BY TOPIC
BLOGS BY AUTHOR
BLOGS BY YEAR
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?
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
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):
The source code for the repeater above
Here is the HTML that this generates:
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
The Repeater control exposes the following 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.