Slide 14.9: The Repeater control (cont.)
Slide 14.11: The Repeater control (cont.)
Home

The Repeater Control (Cont.)


Using the AlternatingItemTemplate Property
You can add an AlternatingItemTemplate element after the ItemTemplate element to describe the appearance of alternating rows of output. In the following example each other row in the table will be displayed in a light grey color.

Related examples can be found at ASP.NET Quickstart.


demo_repeater2.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>
    <AlternatingItemTemplate>
     <tr bgcolor="#e8e8e8">
      <td><%#Container.DataItem("title")%></td>
      <td><%#Container.DataItem("artist")%></td>
      <td><%#Container.DataItem("company")%></td>
      <td><%#Container.DataItem("price")%></td>
     </tr>
    </AlternatingItemTemplate>
    <FooterTemplate>
     </table>
    </FooterTemplate>
   </asp:Repeater>
  </form>
 </body>
</html>