Reloading an Order
Previous  Top  Next

The cart make it real simple to re-load previous or saved orders, to demonstrate this edit the products/LoadCart.aspx page.

The page contains the form shown in the following image:

clip0115

Begin adding the cart functionality by inserting a cart control clip0011

Give the cart an ID of "Cart1" and click "OK", the cart tag will be inserted into the page.

Next insert an Add To Cart From Database control by clicking the clip0009 icon in the insert bar, the following dialog will then appear:

clip0116

Define the properties as shown in the image:

ID = LoadCart1
ConnectionString = ConStr
DBtable = OrderItems
ParamName = TxtOrderID (this is the id of the forms textbox)
AfterAddURL = ../cart/cart.aspx
DataBaseType = OleDb
SelectorField = OrderID
Cart = Cart1
ManualMode = True (check the box)

Next click "Field Mappings" in the left section of the dialog and it will change to show the field mappings, define them as shown below:

clip0117

Using this dialog add the following field mappings:

Cart Field "RawCost" to get it's value from Database Field "Cost"  
Cart Field "ID" to get it's value from Database Field "PartNo"  
Cart Field "Description" to get it's value from Database Field "Description"  
Cart Field "Quantity" to get it's value from Database Field "Quantity"  
 
Next add the following code block to the page:

C#  
<script runat="server">  
void Button1_Click(object sender, System.EventArgs e)  
{  
if(this.TxtOrderID.Text != "")  
{  
this.Cart1.Cancel();  
this.LoadCart1.Add();  
}  
}  
</script>  
 
VB  
<script runat="server">  
Sub Button1_Click(sender As Object, e As System.EventArgs)  
If Me.TxtOrderID.Text <> "" Then  
Me.Cart1.Cancel()  
Me.LoadCart1.Add()  
End If  
End Sub  
</script>  
 
This code will be executed when the user click the "Load Cart" button.

All that's left is to add:

OnClick="Button1_Click"  

To the buttons tag and this page is ready to run, to test it look in the database at the OrderID values and use those values to load each order into the cart.