Overview of Data Controls in ASP.NET 4.0
Part three 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
  3. DataList Controls - ASP.NET data controls (this blog)
  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.

DataList Controls in ASP.NET

An example of a DataList control is shown below:

Example of DataList control

An example of a DataList control

As this diagram shows, a DataList allows you to display records in columns.  This is most useful when you want to display shopping items in a two-dimensional grid.

Avoid DataList controls.  Microsoft don't seem to be exactly throwing their weight behind their future support; see here for example. 

 Source HTML for DataList Controls

The source HTML for the above DataList is as follows:

Source HTML for the DataList above

Source HTML for the DataList above

The RepeatColumns property (shown shaded above) specifies that there will be 2 columns in the final web page.

DataList Events

A DataList control exposes the following events:

DataList events

A DataList has a more exciting life than a repeater, but still has a fairly limited set of events that you can react to.



Microsoft introduced the ListView control in ASP.NET 3.5, to get round the limitations of the DataList control.  If you want to display data in a grid or in columns, use the ListView control instead.

This blog has 0 threads Add post