Some Web controls allow you to specify templates, which are HTML elements that define the layout for a particular portion of a control. For example, in the DataGrid Web control, you can define templates for items, selected items, alternating items, and so on, so that each of these elements can have a custom look.
Note For background information about templates, see Web Forms Controls Templates.
The procedure for creating templates is the same for all controls that support templates.
You can create templates by editing the control directly in the .aspx file.
Note For details about what templates are supported in individual controls, see [xref].
To create a Web control template using ASP+ syntax
<asp:DataList id="DataList1" runat="server"> <template name="ItemTemplate"> </template> </asp:DataList>
<template name="ItemTemplate"> Name: <asp:Label runat="server" Text="<%# Container.DataListItem.Name %>"/> </template>
The following example shows a complete declaration for a DataList Web control with simple templates declared for the Header, Item, and Separator templates:
<asp:DataList id="DataList1" runat=server datasource="<%# MyCollection %>" > <template name="Header"> Items matching your query: </template> <template name="Item"> Name: <asp:Label runat="server" Text="<%# Container.DataListItem.Name %>" /> </template> < template name="Separator" <BR><HR> </ template > </asp:DataList>