ASP.NET
  Home arrow ASP.NET arrow Page 4 - 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 
Mobile Linux 
App Generation ROI 
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 - Ooooh, Bubbles!


    (Page 4 of 5 )

    Suppose you've decided that along with your nicely styled repetition of your inventory, it would be somewhat beneficial to your business for people to actually be able to purchase one or more of the items. A nice way to do that is stick a little button unambiguously labeled 'buy'. When you click 'buy', you want a subroutine that takes the ID of the item you want to buy, and takes you to the next step of credit card processing and such.

    I won't bother with the next step here, but I will show you how to embed a button control in the Repeater, and how to configure the button (child) to make the Repeater (parent) aware of its events. This is called bubbling. Think of bubbles starting at the bottom of a boiling pot, and rising to the surface to pop. That's essentially what's happening; the events/bubbles start at the bottom - the child - and rise to the top – the parent – to be handled.

    To do this, first we add the code to the container, the Repeater, to capture the events. Our repeater will now look like this:

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

    Then, we add the child control, the button to the item template, and the alternating item template if you are using one. It would look like this:

    <asp:button runat="server" text="buy" CommandArgument='<%# Container.DataItem("id") %>' />

    We hide the id of the item in the CommandArgument member of the button, which we will pick up later. Once a user clicks 'buy', this raises an event, which is bubbled up to the repeater, which will hand it off to the following getItem() subroutine:

    Sub getItem( s as object, e as RepeaterCommandEventArgs )

    'response.write( "id: " + e.CommandSource.CommandArgument )

    Dim id as String = e.CommandSource.CommandArgument.ToString()

    Response.redirect( "buy.aspx?intID=" + id )

    End Sub

    As you can see, this subroutine picks up the value from the button control though the CommandArgument member. We could do lots of things with this now, but for simplicity's sake I have just chosen to hand it off to another page ('buy.aspx') with the ID of the desired product.

    More ASP.NET Articles
    More By Justin Cook


     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - 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





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT