asp.net.ph

Skip Navigation LinksHome > ASP.NET Web Forms > Web Forms Server Controls > Web Forms Server Controls Templates

Web Forms Server Controls Templates

ASP.NET Web Forms   Web Forms Server Controls


This article takes a closer look at the various templates used in certain Web server controls, and how you can customize templates to enhance the look and functionality of data-bound list controls, in particular the Repeater, DataList, and DataGrid controls.

A template is basically a representation of page elements that describes the layout for a given portion of a control.

A Repeater, DataList, and DataGrid control is actually composed of heterogeneous portions called items. Each control can have five basic item types: a header, normal data items, alternating data items, separators, and a footer. In addition, the DataList and the DataGrid can have two other item types: the currently selected item, and the item that is currently being edited. Lastly, the DataGrid can also have a pager item.

Basically, you can define templates for each of the different item types that can make up a control ( headertemplate, itemtemplate, footertemplate, and so on ). The way these items are rendered is completely determined by how you implement the control’s templates.

Each template can consist of literal text, HTML elements, and/or other ASP.NET server controls that can, in the case of data items, be bound to a data source. The following examples illustrate basic use of templates.

Binding a DataReader to a Repeater
Run Sample | View Source
Binding a DataReader to a DataList
Run Sample | View Source
Binding a DataReader to a DataGrid
Run Sample | View Source

NOTE: Templates differ from styles. Styles specify the appearance of elements such as font, color, border and so on within a control’s layout. You can use styles without using templates, if all you need to do is change the appearance of the default rendering of a control. You can also use styles with a template to control the appearance of elements that you define within your templates.

More ...
Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note