0
    <asp:Repeater ID="Cart" runat="server" onitemcommand="Cart_ItemCommand">
       <ItemTemplate>
          <p class="cartline">
             <span class="cartvalue cartqty"><asp:TextBox ID="cartQty" runat="server" Text='<%#Eval("shoppingCartQty")%>'></asp:TextBox></span>
             <span class="cartdelete cartadjust">
                <asp:HiddenField ID="cartID" value='<%#Eval("shoppingCartID") %>' runat="server" /> 
                <asp:LinkButton ID="cartDelete" runat="server" CommandName="DeleteFromCart" CommandArgument='<%#Eval("shoppingCartID") %>'><img src="img/but-delete.png" alt="delete item" title="delete shopping cart item" /></asp:LinkButton>
             </span>
          </p>

       </ItemTemplate>
    </asp:Repeater>

<asp:LinkButton ID="cartRecalcButton" CssClass="cartrecalcbutton" runat="server" ToolTip="recalculate your shopping cart" onclick="cartRecalcButton_Click">&nbsp;</asp:LinkButton>

I'm building my first site in C# and I'm stuck on how to iterate through each cartQty and update the database.

I have a stored procedure ready to update each cart row but need to pass the cartID and the cartQty. Ive tried to use foreach (Control x in this.Controls) but to no avail. HELP! (please...)

John Saunders
  • 160,644
  • 26
  • 247
  • 397
ComfortablyNumb
  • 1,448
  • 10
  • 37
  • 64

1 Answers1

1

The repeater does the iteration itself, you don't have to create the loop. Here's the official syntax from w3schools, but a more relevant example would be this. You can use a stored procedure as a datasource, but it's not necessary.

Precious Roy
  • 1,086
  • 1
  • 9
  • 19
  • roy I've got the repeater working fine. But if someone amends the quantity in the cart and clicks the recalculate button, don't I need to read through each row to update the quantity in the database against its corresponding cartID? – ComfortablyNumb Jun 28 '11 at 13:40
  • 1
    there are several ways of updating a row, or calling an event on the changing of an element in the row. If you look at the answer to this question, you could use his syntax to find the row in question, and then execute your stored proc on that record [link](http://goo.gl/Q4Nmz). But I'd probably use some ajax calls, like this guy, in order to do inline editting [link](http://goo.gl/r4nbQ). – Precious Roy Jun 28 '11 at 15:29
  • awesome, just glad you asked a question i know something about. Trying to build my rep on here, at this rate I'll never come close to you. – Precious Roy Jun 29 '11 at 17:10