Hello, I'm struggling with the following issue, and need help with it..
I'm using ASP.NET, and trying to create a primitive webshop. You "buy" services, not products, and you only need to buy them once, so I'd like to filter the cart to add an element only once, no matter how many times a customer trying it. Here's my code, which ought to do this:
public void addItem(string name, string price)
{
GridView kosar = (GridView)this.Master.FindControl("kosarGridView");
bool van = false;
for (int i = 0; i < kosar.Rows.Count; i++)
{
if (kosar.Rows[i].Cells[0].Text == name)
{
van = true;
aa.Text = "aa"; //just for diagnostical purpose
}
}
if (van == false)
{
DataRow product = Cart.NewRow();
product[0] = name;
product[1] = price;
Cart.Rows.Add(product);
}
kosar.DataBind();
}
As you may see, it just compares the two strings, and if they are the same, does nothing, else it adds a new line to the gridview.
Trouble is the two strings are never the same for this method, and I just can't figure it out why. Because they are the same, I've tested it a couple of times.
What am I doing wrong? Please help me out!
Thanks in advance!