![]() ![]() | ||
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 %>" DataMember="authors"> <HeaderTemplate> <tr style="background-color:cyan"> <th>First Name</th> <th>Last Name</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%# DataBinder.Eval(Container, "DataItem.au_fname") %> </td> <td><%# DataBinder.Eval(Container,"DataItem.au_lname") %> </td> </tr> </ItemTemplate> <AlternatingItemTemplate> <tr> <td bgcolor="pink"> <%# DataBinder.Eval(Container, "DataItem.au_fname") %> </td> <td bgcolor="pink"> <%# DataBinder.Eval(Container,"DataItem.au_lname") %> </td> </tr> </AlternatingItemTemplate> <FooterTemplate> </FooterTemplate> </asp:Repeater> </table> </form>
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 DataSet11.Clear() OleDbDataAdapter1.Fill(DataSet11) Repeater1.DataBind() End Sub
The result appears in Figure 23.11. For more details on this example, see the In Depth section of this chapter.
![]() ![]() | ||