Server Control Inline Template Syntax
Customizes the look and layout of ASP.NET server controls that support templates.
<templatename>
Server control, data-binding syntax, and so on
</templatename>
Markup Tags
- templatename
The name of the ASP.NET server control template.
Remarks
The following Web server controls support templates: Repeater, DataList, and DataGrid. You can use template properties to customize the appearance of server controls on the pages in which they appear. You can include multiple template properties in a server control declaration. Template syntax must be contained between the opening and closing tags of one of these server controls or between the opening and closing tags of a custom server control you have created. For information about how to use inline templates, see Web Server Controls Templates.
You can also define your own templates when you develop custom server controls. For information about developing controls that define and use inline style templates, see Developing Templated Controls.
Example
The following example shows how to declare the HeaderTemplate, AlternatingItemTemplate, ItemTemplate, and FooterTemplate templates in a Repeater Web server control. Each of these templates is associated with a property of the Repeater class.
<%@ Page Language="C#" %>
<html>
<head>
<script language="C#" runat="server">
void Page_Load(Object Sender, EventArgs e) {
if (!IsPostBack) {
ArrayList values = new ArrayList();
values.Add("Apple");
values.Add("Orange");
values.Add("Pear");
values.Add("Banana");
values.Add("Grape");
Repeater1.DataSource = values;
Repeater1.DataBind();
}
}
</script>
</head>
<body>
<h3><font face="Verdana">Repeater Example</font></h3>
<form runat=server>
<b>Repeater1:</b>
<p>
<asp:Repeater id=Repeater1 runat="server">
<HeaderTemplate>
<table border=1>
</HeaderTemplate>
<AlternatingItemTemplate>
<tr>
<td><b> <%# Container.DataItem %> </b> </td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr>
<td> <%# Container.DataItem %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<p>
</form>
</body>
</html>
[Visual Basic]
<%@ Page Language="VB" %>
<html>
<head>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim values As New ArrayList()
values.Add("Apple")
values.Add("Orange")
values.Add("Pear")
values.Add("Banana")
values.Add("Grape")
Repeater1.DataSource = values
Repeater1.DataBind()
End If
End Sub
</script>
</head>
<body>
<h3><font face="Verdana">Repeater Example</font></h3>
<form runat=server>
<b>Repeater1:</b>
<p>
<asp:Repeater id=Repeater1 runat="server">
<HeaderTemplate>
<table border=1>
</HeaderTemplate>
<AlternatingItemTemplate>
<tr>
<td><b> <%# Container.DataItem %> </b> </td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr>
<td> <%# Container.DataItem %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<p>
</form>
</body>
</html>
See Also
Developing Templated Controls | Custom Server Control Syntax | ASP.NET Web Forms Syntax