Hi There,
I'm getting an error when I try to update multiple rows from shopping cart. When I have one row it works fine but when I have multiple rows it gives me the error "Collection was modified; enumeration operation may not execute. " after the first iteration of the loop.
Could someone help me out with the syntax please?
Sean
!--- code
Sub ChangeQuantity(ByVal send As Object, ByVal E As EventArgs)
Dim i As Int32 = 0
Dim strCode As String = ""
Dim intusercode As Int32 = 0
' For i = 0 To cart.Items.Count - 1
For Each dataItem As RepeaterItem In cart.Items
Dim ItemQuantity As TextBox = (CType(dataItem.FindContro
l("ItemQua
ntity"), TextBox))
Dim txtcode As TextBox = (CType(dataItem.FindContro
l("txtcode
"), TextBox))
Dim txtitemnumber As Label = (CType(dataItem.FindContro
l("lblPite
mnumber"),
Label))
Dim lblprice As Label = (CType(dataItem.FindContro
l("lblpric
e"), Label))
If Not txtcode.Text = "" Then
strCode = GetValidCode(txtcode)
If strCode Is Nothing Then 'if the user does not have a valid code then call the function
Call UpdateCart(ItemQuantity, txtcode, txtitemnumber, lblprice, intusercode)
Else 'if the user has a valid code then look it up
Session("THECODE") = strCode
intusercode = 1
Call GetDistributorPrice(ItemQu
antity, txtcode, txtitemnumber, lblprice, intusercode)
End If
Else
'if the code is nothing then call the function
Call UpdateCart(ItemQuantity, txtcode, txtitemnumber, lblprice, intusercode)
End If
'Exit For
Next
End Sub
!--- repeater code
<asp:repeater id="cart" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="3" style="background-color:#F
6F6F6; border-collapse:collapse">
<tr>
<th>
Number</th>
<th>
Title</th>
<th>
Price</th>
<th>
Quantity</th>
<th>
MTA / Reseller Code</th>
<th>
Amount</th>
<th>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center">Item Number:
<%# Container.DataItem("Pitemn
umber") %>
<asp:Label id="lblPitemnumber" runat="server" ReadOnly="True" Visible="false" Text='<%# Container.DataItem("Pitemn
umber") %>'>
</asp:Label>
</td>
<td align="left">Item Name:
<asp:Label id="lblPitemname" runat="server" ReadOnly="True" Visible="true" Text='<%# Container.DataItem("Pname"
) %>'>
</asp:Label>
</td>
<td align="right">Item Price:
<asp:Label id="lblprice" runat="server" ReadOnly="True" Visible="true" Text='<%# Container.DataItem("Pprice
") %>'>
</asp:Label>
<asp:Label id="lblPhandling" runat="server" ReadOnly="True" Visible="False" Text='<%# Container.DataItem("Phandl
ing") %>'>
</asp:Label>
</td>
<td align="center">
<asp:TextBox id="ItemQuantity" runat="server" Text='<%# Container.DataItem("Pitemq
uantity") %>' MaxLength="2" Style="width:30px; text-align:right"/>
</td>
<td>
<asp:TextBox id="txtcode" runat="server" MaxLength="11" Style="width:100px; text-align:right" /></td>
<td align="right"><b><%# FormatNumber(GetItemAmount
(Container
.DataItem(
"Pprice"),
Container.DataItem("pitemq
uantity"))
, 2) %></b></td>
</ItemTemplate>
<FooterTemplate>
<tr>
<th align="right" colspan="4">
Postage & Handling:
</th>
<td align="right"><b><%# FormatCurrency(GetOrderShi
pping()) %></b></td>
</tr>
<tr>
<th align="right" colspan="4">
Order Total:
</th>
<td align="right"><b><%# FormatCurrency(GetOrderTot
al()) %></b></td>
<td>
<asp:Button Text="Update" class="small" runat="server" onclick="ChangeQuantity" ID="Button1"
NAME="Button2" />
</td>
</tr>
</FooterTemplate>
</asp:repeater>
Start Free Trial