Slide 14.8: The Repeater control
Slide 14.10: The Repeater control (cont.)
Home

The Repeater Control (Cont.)


The previous program takes the following steps:
  1. First, import the System.Data namespace.
       <%@ Import Namespace="System.Data" %>
  2. Next, create a DataSet for the XML file and load the XML file into the DataSet when the page is first loaded.
  1. Then create a Repeater control in an .aspx page where

    • The contents of the HeaderTemplate element are rendered first and only once within the output.

    • The contents of the ItemTemplate element are repeated for each record in the DataSet.

    • The contents of the FooterTemplate element are rendered once within the output.
 <html>
  <body>
   <form runat="server">  
    <asp:Repeater
       id="cdcatalog" 
       runat="server">
     <HeaderTemplate>
      ...
     </HeaderTemplate>
     <ItemTemplate>
      ...
     </ItemTemplate>
     <FooterTemplate>
      ...
     </FooterTemplate>
    </asp:Repeater>
   </form>
  </body>
 </html>
  1. Finally, add the script that creates the DataSet and binds the mycdcatalog DataSet to the Repeater control. We also fill the Repeater control with HTML tags and bind the data items to the cells in the ItemTemplate section with the method
       <%# Container.DataItem( "fieldname" ) %>
    The class Container encapsulates zero or more components. The Container.DataItem refers to the data source used by the repeater.