Slide 14.7: XML files (cont.)
Slide 14.9: The Repeater control (cont.)
Home

The Repeater Control


The Repeater control is used to display a repeated list of items that are bound to the control. The Repeater control may be bound to a database table, an XML file, or another list of items. Here we will show how to bind an XML file to a Repeater control. We will use the XML file cdcatalog.xml in our examples:

Related examples can be found at ASP.NET Quickstart.


demo_repeater1.aspx

Web
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Import Namespace="System.Data" %>
<script language="VB" runat="server">
 Sub Page_Load(s As Object, e As EventArgs ) Handles Me.Load
  If Not Page.IsPostBack then
   dim mycdcatalog = New DataSet
   mycdcatalog.ReadXml( MapPath( "cdcatalog.xml" ) )
   cdcatalog.DataSource = mycdcatalog
   cdcatalog.DataBind( )
  End If
 End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" > 
 <body> 
  <form runat="server">
   <asp:Repeater id="cdcatalog" runat="server">
    <HeaderTemplate>
     <table border="1" width="100%">
      <tr>
       <th>Title</th>
       <th>Artist</th>
       <th>Company</th>
       <th>Price</th>
      </tr>
    </HeaderTemplate>
    <ItemTemplate>
      <tr>
       <td><%#Container.DataItem("title")%></td>
       <td><%#Container.DataItem("artist")%></td>
       <td><%#Container.DataItem("company")%></td>
       <td><%#Container.DataItem("price")%></td>
      </tr>
    </ItemTemplate>
    <FooterTemplate>
     </table>
    </FooterTemplate>
   </asp:Repeater>
  </form>
 </body>
</html>