JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Repeaters

When you use a repeater in a Web form, the HTML is up to you. You can create the various templates you need in HTML, using elements like <HeaderTemplate>, <ItemTemplate>, and so on.

We saw how to do this in the WebRepeaters example on the CD-ROM, as discussed in the In Depth section of this chapter. That example displays the authors table in the pubs database using alternating lines, as you see in Figure 23.11. Here's how to create the necessary templates by editing the HTML directly:

<form id="Form1" method="post" runat="server">
  <table width="100%">
<asp:Repeater id=Repeater1 runat="server" DataSource="<%# DataSet11 %>"
  <tr style="background-color:cyan">
     <th>First Name</th>
     <th>Last Name</th>
     <td><%# DataBinder.Eval(Container, "DataItem.au_fname") %>
     <td><%# DataBinder.Eval(Container,"DataItem.au_lname") %>
     <td bgcolor="pink">
     <%# DataBinder.Eval(Container, "DataItem.au_fname") %> </td>
     <td bgcolor="pink">
     <%# DataBinder.Eval(Container,"DataItem.au_lname") %> </td>


And, of course, you have to fill the data adapter and bind the repeater as well:

Private Sub Page_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

The result appears in Figure 23.11. For more details on this example, see the In Depth section of this chapter.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor