1 / 8

CIS 375—Web App Dev II

CIS 375—Web App Dev II. ASP .NET 8 More Binding. The Repeater Control 1. 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.

xantha-beck
Download Presentation

CIS 375—Web App Dev II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 375—Web App Dev II ASP .NET 8 More Binding

  2. The Repeater Control 1 • 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. • We will use cdcatalog.xml in our examples. <?xml version="1.0" encoding="ISO-8859-1"?><catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd>

  3. The Repeater Control 2 • The code starts out by importing the ____________, using a DataSet object, associating it with the XML file, and binding when the page first loads: <%@ Import Namespace = "System.Data" %> <script runat = "server"> sub Page_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>

  4. The Repeater Control 3 • Then we create a Repeater control in an .aspx page. • The contents of the <HeaderTemplate> element are rendered first and only once within the output. • Then the contents of the <ItemTemplate> element are repeated for each “________" in the DataSet • Last, the contents of the <FooterTemplate> element are rendered once within the output.

  5. The Repeater Control 4--Example <html> <body> <form runat="server"> <asp:Repeater id="cdcatalog" runat="server"> <HeaderTemplate> <table border="1" width="100%"> <tr> <th>Title</th> <th>Artist</th> <th>Country</th> <th>Company</th> <th>Price</th> <th>Year</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%#Container.DataItem("title")%></td> <td><%#Container.DataItem("artist")%></td> <td><%#Container.DataItem("country")%></td> <td><%#Container.DataItem("company")%></td> <td><%#Container.DataItem("price")%></td> <td><%#Container.DataItem("year")%></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </form> </html> </body>

  6. Alternating and Separating • You can add an <AlternatingItemTemplate> element following the <ItemTemplate> element to describe the ___________ of alternating rows. (Ex.) <AlternatingItemTemplate> <tr bgcolor="#e8e8e8"> <td><%#Container.DataItem("title")%></td> … <td><%#Container.DataItem("year")%></td> </tr> </AlternatingItemTemplate> • The <SeparatorTemplate> element can be used to describe a separator between each record. (Ex.) <SeparatorTemplate> <tr><td colspan="6"><hr /></td> </tr> </SeparatorTemplate>

  7. The DataList Control • The DataList control, like the Repeater control, is used to display a repeated list of items that are bound to the control. • However, the DataList control adds a _______ around the data items by default. • Instead of • <form runat="server"> • <asp:Repeater id="cdcatalog" runat="server"> • We have • <form runat="server"> • <asp:Datalist id="cdcatalog" runat="server"> • DataList Example

  8. Using Styles • Creating styles for a DataList: <asp:DataList id="cdcatalog" runat="server" cellpadding="2" backcolor="#e8e8e8" width="100%" headerstyle-font-name="Verdana" headerstyle-font-size="12pt" headerstyle-horizontalalign="center" itemstyle-backcolor="#778899" alternatingitemstyle-backcolor="#e8e8e8" footerstyle-font-size="9pt" footerstyle-font-italic="true"> • Styles Example • AlternatingItem Style Example

More Related