Remove items from cart vb.net
Hi I have create a shopping cart in vb.net, so far i can add items to cart but cant empty or remove items from cart. can anyone help me please?
this is the code I have so far:-
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div id="mycart">
<br />
Your shopping cart:<br />
<table style="width: 500px" align="center" cellspacing="0"
cellpadding="0" border="0">
<tr>
<td style="width: 286px; height: 153px">
<asp:ListBox ID="lstCart" runat="server"
Width="267px" Height="135px">
</asp:ListBox>
</td>
<td style="height: 153px">
开发者_运维技巧 <asp:Button ID="btnRemove" runat="server"
Width="100px" Text="Remove Item" /><br /><br />
<asp:Button ID="btnEmpty" runat="server"
Width="100px" Text="Empty Cart" />
</td>
</tr>
</table>
<br />
<asp:Button ID="btnContinue" runat="server"
PostBackUrl="~/index.aspx" Text="Continue Shopping" />
<asp:Button ID="btnCheckOut" runat="server" PostBackUrl="~/CheckOut.aspx" Text="Check Out" /><br />
<br />
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</div>
Partial Class MyCart
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load#
Dim myCart = ShoppingCart.Instance
lstCart.Items.Clear
For Each item As CartItem In myCart.Items
lstCart.Items.Add(item.Description)
Next
End Sub
End Class
Should just be what you've alerady got minus the for each, ie:
lstCart.Items.Clear
Edit: just noticed your buttons in the HTML, to get them working you'll want something like :
Protected Sub btnRemove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRemove.Click
lstCart.Items.Remove(lstCart.SelectedItem)
End Sub
Protected Sub btnEmpty_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEmpty.Click
lstCart.Items.Clear
End Sub
Rene
精彩评论