Asp.net| Create | templates | syntax
To create a WEB server control template using asp.net syntax
- 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:d Atalist>
- 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>
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 a property is missing from a Web server control element
runat="server"
, this error is displayed. Point to the information icon (), and a tooltip appears that contains detailed information about the error.