I am having a problem with the code below especially bolded part. I have built a shopping cart page where if they select the item 'Real Estate Forms 2d' there will be a sales tax added for that item. If they select any other item they will not have a sales tax. With my current code below it doesn't access sales tax for that one item or any other item. If I change the else part of the code to 0.06 it will show sales tax for all items. It is not recognizing the 1st condition of the if statement. Another key note to point out is that item.Name where Name part of the class definition of Webexcellence.EComm.ShoppingCartItem. Can someone please assist me in what I am doing wrong and what I need to do to fix this.

# if (Session["CartID"] != null)  
#     {  
#         ShoppingCart objCart = ShoppingCart.Resume(Convert.ToInt32(Session["CartID"]));  
#         if (objCart == null || objCart.Count == 0)  
#         {  
#             blnNoCart = true;  
#         }  
#         else  
#                     {  
#                         // calculate shipping  
#                         //int intTotalItems = 0;  
#                         //foreach (ShoppingCartItem objItem in objCart.GetItem())  
#                         //{  
#                         //    intTotalItems += objItem.Quantity;  
#                         //}  
#                         //double dblShipping = intTotalItems * 6;  
#                         double dblShipping = 6;  
#   
#                         // show items  
#                       <strong>  foreach( ShoppingCartItem item in objCart.GetItem())
{
    if(item.Name == "Real Estate Forms 2d");
#                         {  
#                            objCart.TaxRate = 0.06;  
#                         {  
#                         objCart.TaxRate = 0.00;  
#                         }</strong>  
#                   <strong>    }</strong>                              
#                         rptCartItems.DataSource = objCart.GetItem();  
#                         rptCartItems.DataBind();  
#   
#                         lblCartSubtotal.Text = String.Format("{0:c}", objCart.TotalValue);  
#                         lblCartTax.Text = String.Format("{0:c}", objCart.TaxRate * (dblShipping + objCart.TotalTaxableValue));  
#                         lblCartShipping.Text = String.Format("{0:c}", dblShipping);  
#                         lblCartTotal.Text = String.Format("{0:c}", objCart.TotalValue + (objCart.TaxRate * (dblShipping + objCart.TotalTa

ShoppingCartItem class

# namespace Webexcellence.EComm  
# {  
#     public class ShoppingCartItem  
#     {  
#         public ShoppingCartItem(int intProductID, double dblPrice);  
#   
#         public int ItemID { get; set; }  
#         public string Name { get; set; }  
#         public double Price { get; set; }  
#         public int ProductID { get; set; }  
#         public Hashtable Properties { get; set; }  
#         public int Quantity { get; set; }  
#         public bool Taxable { get; set; }  
#         public double TotalValue { get; }  
#   
#         public override bool Equals(object obj);  
#         public override int GetHashCode();  
#     }

Anyone with any ideas on this please?

93 views and not one person can offer any assistance. Please I am begging for help at this point.

Not sure if the code you provided above is exactly the same or messed up in the editor but look the foreach loop code below. Not the debugging statement:

foreach (ShoppingCartItem item in objCart.GetItem())
        {
           Response.Write(item.Name.ToString()+ "<br//>");
           
          if (item.Name == "Real Estate Forms 2d")
            {
                objCart.TaxRate = 0.06;
            }
            else
            {
                objCart.TaxRate = 0.00;
            }
        }

Make sure the itemName matches letter to letter including space.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.