0
public void BindCartNumber()
        {
            if (Request.Cookies["CartPID"] != null)
            {
                string CookiePID = Request.Cookies["CartPID"].Value.Split('=')[1];
                string[] ProductArray = CookiePID.Split(',');
                int ProductCount = ProductArray.Length;
                pCount.InnerText = ProductCount.ToString();
            }
            else
            {
                pCount.InnerText = 0.ToString();
            }
        }

well i was doing college project online shop and i want to number of added products in cart button but it is teling me the error

  • The only place I see you accessing an array by index is here: string CookiePID = Request.Cookies["CartPID"].Value.Split('=')[1]; You might want to run in debug mode and see what the value of string Request.Cookies["CartPID"].Value actually is as I suspect there is no '=' there, hence no element at 1 when you split it. – bschellekens Oct 08 '21 at 16:14
  • Check `Request.Cookies["CartPID"].Value` actually contains `=` – Ermiya Eskandary Oct 08 '21 at 16:15
  • Possible duplicate of https://stackoverflow.com/q/24812679/4800344 – Ermiya Eskandary Oct 08 '21 at 16:15
  • Does this answer your question? [What is an "index out of range" exception, and how do I fix it?](https://stackoverflow.com/questions/24812679/what-is-an-index-out-of-range-exception-and-how-do-i-fix-it) – Ermiya Eskandary Oct 08 '21 at 16:15
  • Can you share the value of Request.Cookies["CartPID"].Value ? Also, can you confirm that this is the line throwing the error? – bschellekens Oct 08 '21 at 16:43
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 09 '21 at 19:18

0 Answers0