Click here to Skip to main content
Sign Up to vote bad
good
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.To.Add(txtTo.Text)
        MyMail.To.Add(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
        SmtpMail.Send(MyMail)
 
        MsgBox("Your order has been submitted for processing. A copy has been sent to your email as well.")
 
Any help is appreciated.
Thanks
Posted 17 Nov '12 - 19:17

Comments
aspnet_regiis -i - 18 Nov '12 - 6:06
and the question is?
TorstenH. - 19 Nov '12 - 4:13
- 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:52
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.

2 solutions

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
 

Sorry,
Please replace the & symbol with + symbol
  Permalink  
Comments
Member 9608236 - 28 Nov '12 - 18:55
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:30
Sorry..... Replace the "&" symbol with the "+" symbol.
Member 9608236 - 11 Dec '12 - 23:56
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.
 
CHANGE CODE TO THIS...
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
 
to
 
For i = 0 to lstCart.Items.Count -1
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 365
1 OriginalGriff 315
2 Slacker007 240
3 Dave Kreskowiak 212
4 Aarti Meswania 210
0 Sergey Alexandrovich Kryukov 8,893
1 OriginalGriff 7,134
2 CPallini 3,678
3 Rohan Leuva 3,036
4 Maciej Los 2,428


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid