NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Creating Web Control Templates

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

  1. In the .aspx file, insert a <template> element inside the control, using the NAME attribute of the element to identify what template you are creating:
    <asp:DataList id="DataList1" runat="server">
       <template name="ItemTemplate">
       </template>
    </asp:DataList>
  2. Inside the <template> element, add HTML text and other controls as the template's content. Include property and data-binding values for the embedded controls using normal syntax:
    <template name="ItemTemplate">
       Name: <asp:Label runat="server"
              Text="<%# Container.DataListItem.Name %>"/>
    </template>
  3. Repeat Steps 1 and 2 for each template you want to create.

    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>
    

See Also

Web Forms Controls Templates | Web Forms Server Controls