Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET eCommerce email
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 20:17pm
Comments
aspnet_regiis -i at 18-Nov-12 6:06am
   
and the question is?
TorstenH. at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
v2
Comments
Member 9608236 at 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 at 1-Dec-12 21:30pm
   
Sorry..... Replace the "&" symbol with the "+" symbol.
Member 9608236 at 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!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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)



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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100