ASP.NET
  Home arrow ASP.NET arrow Page 3 - Making Use of the Repeater Web Server Cont...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Making Use of the Repeater Web Server Control
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2004-06-28

    Table of Contents:
  • Making Use of the Repeater Web Server Control
  • Get the Data
  • Can You Repeat That Please?
  • Ooooh, Bubbles!
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Making Use of the Repeater Web Server Control - Can You Repeat That Please?


    (Page 3 of 5 )

    Now that we have the data and the repeater is bound to it, you're going to need to know how to actually make use of it. I mentioned that there are five different template areas, and I'll list them now:

    1. HeaderTemplate – The header (for example, you would place your starting '<table>' HTML code here.
    2. ItemTemplate – which DataItem fields are displayed, and how.
    3. AlternatingItemTemplate – How are the odd items displayed? By odd I mean odd-indexed, not the strange items (I don't think .Net is smart enough to pick out which items are strange anyways). This would be useful if you want to perhaps change the background color of every other item, which helps to visually distinguish them.
    4. SeparatorTemplate – Perhaps you want to use something to separate the items, such as a line ('<hr />').
    5. FooterTemplate – Finally, the footer. If you placed <table> in your header, it would be wise to put </table> here.

    Of the five templates, the only one that .Net actually requires you to provide is the ItemTemplate. Once it knows which items to display, it will happily do about its business not even caring that you omit the others. You can even configure the header and leave out the footer without encountering any errors, though I'm not sure I understand why you would want to...

    This is how you could use the templates:

    <asp:Repeater id="prodRepeater" runat="server">

    <HeaderTemplate>

    <table cellpadding="3" border="0" cellspacing="0">

    </HeaderTemplate>

    <ItemTemplate>

    <tr>

    <td style="font-family:verdana;font-size: 11px;">

    Desc: <%# Container.DataItem("description") %><br />

    Mfg: <%# Container.DataItem("manufacturer") %><br />

    Color: <%# Container.DataItem("color") %><br />

    Cost: <%# FormatCurrency( Container.DataItem("price")) %>

    </td>

    <td style="font-family:verdana;font-size: 11px;">Picture: <br />

    <img src="<%# Container.DataItem("imgPath") %>" />

    </td>

    </tr>

    </ItemTemplate>

    <AlternatingItemTemplate>

    <tr style="background-color:#666666;color:#ffffff;">

    <td style="font-family:verdana;font-size: 11px;">

    Item: <%# Container.DataItem("description") %><br />

    Mfg: <%# Container.DataItem("manufacturer") %><br />

    Color: <%# Container.DataItem("color") %><br />

    Cost: <%# FormatCurrency( Container.DataItem("price")) %>

    </td>

    <td style="font-family:verdana;font-size: 11px;">Picture: <br />

    <img src="<%# Container.DataItem("imgPath") %>" />

    </td>

    </tr>

    </AlternatingItemTemplate>

    <SeparatorTemplate>

    <tr><td style="height:2px;background-color:#333333" colspan="2"></td></tr>

    </SeparatorTemplate>

    <FooterTemplate>

    </table>

    </FooterTemplate>

    </asp:Repeater>

    This would give you a nice little table with every other row colored dark gray. Of course, having the SeparatorTemplate insert a two pixel dark gray row in between each is a little redundant, but I thought it appropriate to use for the sake of the tutorial. Now let's get into event bubbling, which would be absolutely vital in an e-commerce situation.

    More ASP.NET Articles
    More By Justin Cook


     

    ASP.NET ARTICLES

    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway