Hi everyone, I've got a shopping cart with a total amount label, this works perfect with the products, if a product quantity is changed the label also changes. I have a shipping type drop down list determined by which region the user is, I would like the total amount label to add this cost to but can't seem to get it to work. I've used a stored procedure, which I have executed and it works.
Here is my code;
Checkout.aspx.cs
public partial class Checkout : System.Web.UI.Page
{
decimal shippingCost;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
PopulateControls();
}
// fill controls with data
private void PopulateControls()
{
// get the items in the shopping cart
DataTable dt = ShoppingCartAccess.GetItems();
// populate the list with shopping cart content
grid.DataSource = dt;
grid.DataBind();
grid.Visible = true;
// ******* display the total amount
decimal amount = ShoppingCartAccess.GetTotalAmount() + shippingCost;
totalAmountLabel.Text = String.Format("{0:c}", amount);
// check customer details
bool addressOK = true;
// bool cardOK = true;
if (Profile.Address1 + Profile.Address2 == ""
|| Profile.ShippingRegion == ""
|| Profile.ShippingRegion == "Please Select"
|| Profile.Country == "")
{
addressOK = false;
}
// report/hide place order button
if (!addressOK)
{
InfoLabel.Text =
"You must provide a valid address before placing your "
+ "order.";
}
else
{
InfoLabel.Text =
"Please confirm that the above details are "
+ "correct before proceeding.";
}
placeOrderButton.Visible = addressOK; // && cardOK;
shippingSelection.Visible = addressOK; // && cardOK;
// populate shipping selection
if (addressOK) //&& cardOK
{
int shippingRegionId = int.Parse(Profile.ShippingRegion);
List<ShippingInfo> shippingInfoData =
CommerceLibAccess.GetShippingInfo(shippingRegionId);
foreach (ShippingInfo shippingInfo in shippingInfoData)
{
shippingSelection.Items.Add(
new ListItem(shippingInfo.ShippingType,
shippingInfo.ShippingID.ToString()));
}
shippingSelection.SelectedIndex = 0;
}
}
// get shipping cost
protected void shippingSelection_SelectedIndexChanged(object sender, EventArgs e)
{
int shippingId = 0;
int.TryParse(shippingSelection.SelectedValue, out shippingId);
// get tax ID or defalut to "No Tax"
string shippingRegion =
(HttpContext.Current.Profile as ProfileCommon).ShippingRegion;
int taxId;
switch (shippingRegion)
{
case "2":
taxId = 1;
break;
default:
taxId = 2;
break;
}
shippingCost = CommerceLibAccess.GetShippingCost(shippingId);
}