The ASP.NET environment is the premier development environment for creating dynamic server-side content a key element of which is the display of information from data sources. Displaying data on a web page which is bound to information in a database is a very common requirement in web applications. In ASP.NET version 1, the main control for achieving this was the DataGrid. In the current release of ASP.NET, version 3.5, the DataGrid is conspicuously absent from the Toolbox in Visual Web Developer. In fact, although the DataGrid can still be used in ASP.NET pages and will work fine, it is now deprecated. The good news is that there is a good choice of more powerful new controls which have taken its place. Four of these controls (GridView, DataList, Repeater and List View) are suitable for displaying multiple records from a data source and then there are another two (FormView and DetailsView) which are used to display only one record at a time.

Perhaps the most widely-used of ASP.NET’s DataBound controls is the GridView. It displays data items in an automatically-generated table and has a rich set of easily-configurable options. Options include the ability to customize columns and to include custom content in columns such as images or any other relevant HTML column. Command columns can also be added containing links which will enable the user to edit and delete records. The control also supports paging and sorting.

The DataList control also automatically generates a table when it produces its output. However, unlike the GridView control, it allows the display of more than one record per row using its RepeatColumns property. The DataList is also template-driven, requiring the use of an ItemTemplate containing dynamic data. The elements placed inside the ItemTemplate are rendered once for each item in the bound data.

ItemTemplate elements are also used by The Repeater Control to format its output. However, since it does not automatically generate a table, the Repeater offers considerable flexibility of layout. Output can be rendered as paragraphs, as a series of DIV elements, an ordered list, an unordered list or a customized table.

ASP.NET 3.5 introduced us to the ListView control, which also uses templates for displaying its output. However, it is far more sophisticated, allowing the use of a variety of templates, for example: a LayoutTemplate for specifying the overall container for the data; an ItemTemplate for specifying the rendering of each item of data; an ItemSeparator template, used to specify the content displayed between items of data; and so on. The ListView control also supports paging, sorting and editing records as well as the creation of new records.

ASP.NET 3.5 offers a choice of two controls for displaying single items of data: the DetailsView and the FormView. The DetailsView resembles GridView in that it displays its output in an automatically-generated HTML table. The other single record data bound control, the FormView, resembles the ListView control, in that it is entirely template driven. Both of the single record controls support paging and sorting and allow you to edit and delete records as well as adding new ones.

Are you looking for training on Building websites with ASP.NET. We offer Microsoft ASP.NET on-site courses in London and all over the UK.

Tagged with:

Filed under: Web Development

Like this post? Subscribe to my RSS feed and get loads more!