Click here to Skip to main content
15,902,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

im having an issue trying to get the items in the shopping cart which is displayed using a listbox to also be displayed in the email which gets sent after the order is processed, one to admin and a receipt to the customer.

Protected Sub btnProOrd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProOrd.Click
    Dim sName As String, sEmail As String, sAddress As String, sSub As String
    Dim sPCode As String, sState As String, sOrder As String, sPayment As String

    sName = Trim(CusName.Text)
    sEmail = Trim(CusEmail.Text)
    sAddress = Trim(CusAddr.Text)
    sSub = Trim(CusSub.Text)
    sPCode = Trim(CusPCode.Text)
    sState = Trim(CusState.Text)
    sPayment = Trim(lstCardType.Text)
    sOrder = Trim(lstCart.Items.ToString)

    Dim MyMail As New MailMessage()
    MyMail.From = New MailAddress(CusEmail.Text)

    MyMail.Body = "New Order Recieved" + vbNewLine + "Customer Name" + " " + sName + vbNewLine + "Customer Address" + vbNewLine + sAddress + vbNewLine + sSub + " " + sPCode + " " + sState + vbNewLine + vbNewLine + "Payment Method" + " " + sPayment + vbNewLine + "Customer Order" + vbNewLine + sOrder

    Dim SmtpMail As New SmtpClient

    MsgBox("Your order has been submitted for processing. A copy has been sent to your email as well.")

Any help is appreciated.
bbirajdar 18-Nov-12 6:06am    
and the question is?
TorstenH. 19-Nov-12 4:13am    
- what kind of web shop do you use?
Where should you retrieve that info?
- what is the problem?
Please be more specific.
Member 9608236 21-Nov-12 19:52pm    
ive used a database to display the products, and a listbox which displays the shopping cart once the customer clicks add to cart.

the problem i am having is getting the items which are in the shopping cart to be displayed in the email which is sent after the customer enters their shipping and banking details.

Instead of your line...

sOrder = Trim(lstCart.Items.ToString)

use a loop and loop through the items

For i = 0 to lstCart.Items.count
 sOrder = sOrder & lstCart.Items(i)
Next i

Please replace the & symbol with + symbol
Share this answer
Member 9608236 28-Nov-12 18:55pm    
Thanks for your help Zaf, i get an error message with this code.

"Operator '&' is not defined for types 'String' and 'system.web.UI.WebControls.ListItem'."
Zaf Khan 1-Dec-12 21:30pm    
Sorry..... Replace the "&" symbol with the "+" symbol.
Member 9608236 11-Dec-12 23:56pm    
Hi Zaf,

i have finally had a chance to try this, and i get the exact same error message, i try to run it anyway as sometimes Visual Studio takes a minute to recognise it but it still doesnt work!
Hello Member 9608236,

I can only assume there is an error in the code I gave you.
And upon a second look at it, yes there is!

As the lstCart.Items collection is ZERO based and starts at ZERO and NOT ONE, in the code block i posted above the value of the variable 'i' is exceeding the number of items in the list.

So you can change your code to this and if you STILL get an error then the error is elsewhere and NOT in the code block I posted. In which case you will have to post your error details in more detail.

For i = 0 to lstCart.Items.count - 1
 sOrder = sOrder & lstCart.Items(i)
Next i

I have changed the first line...
For i = 0 to lstCart.Items.Count


For i = 0 to lstCart.Items.Count -1
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900