troubleshooting Question

property or indexer cannot be assigned to it is read only

Avatar of niceoneishere
niceoneishere asked on
.NET ProgrammingC#ASP.NET
7 Comments1 Solution2920 ViewsLast Modified:
Hello everyone,

My website is built in C# and ASP.NET 2.0 using sql 2005 database.

I am trying to apply a simple promo code 30% off the subtotal of an order. So I tried using the code like below

protected void btUpdate_Click(object sender, EventArgs e)

        Order currentOrder = Basket.Order;

        string tbcodeValue = this.tbpromo.Text.Trim().ToUpper();

        string[] validCodes = new string[] { "AB30, FF30" };
        if (!((IList<string>)validCodes).Contains(tbcodeValue))
            lbmessage.Text = "Invalid Promo Code. Please enter again";
            currentOrder.PromotionCode = tbcodeValue;
            currentOrder.Subtotal = (0.70 * currentOrder.Subtotal);
            this.lShipping.Text = currentOrder.Shipping.Cost.ToString("c");
            this.lSubtotal.Text = currentOrder.Subtotal.ToString("c");
            this.lTotal.Text = currentOrder.TotalCost.ToString("c");
            lbmessage.Text = "30% discount applied to your order.";

but when I try to test it out, i am getting the following error

 error CS0200: Property or indexer 'Order.Subtotal' cannot be assigned to -- it is read only
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)

How can I update the Subtotal.

Thanks a bunch!!
Ioannis Paraskevopoulos

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros