In the. aspx file, insert the element into the control to identify the template you are creating:
<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
</ItemTemplate>
</asp:DataList>
In the template element, add HTML text and other controls as the contents of the template. Includes properties and data-bound values for embedded controls that use general syntax:
<ItemTemplate>
Name: <asp:Label runat="server"
Text="<%# Container.DataListItem.Name %>"/>
</ItemTemplate>
Repeat steps 1 and 2 for each template that you want to create.
The following example shows a full declaration of the DataList Web server control with a simple template declared for the Header, Item, and Separator templates.
<asp:datalist id="DataList1" runat=Server >
<HeaderTemplate>
Items matching your query:
</HeaderTemplate>
<ItemTemplate>
Name: <asp:Label id=Label1 runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.EmployeeName")
%>'></asp:Label>
</ItemTemplate>
<SeparatorTemplate>
<br> </SeparatorTemplate>
</asp:datalist></p>
Note If the Web Forms designer does not render a Web server control correctly, it displays a gray box showing the text "Error creating the control." This usually means that the control's ASP.net syntax is incorrect-for example, if the runat= "server" attribute is missing from a Web server control element, this error is displayed. Point to the information icon (), and a tooltip appears that contains detailed information about the error.