I'm trying to improve the compare list, it's almost complete but there is something wrong with the cookie which is blocking me.
I guess a picture will explain the context better than me :
http://img509.imageshack.us/img509/1092/comparelist.th.jpg
The dropDownLists contains the category product list of the product chosen. When I select another product in the dropdownlist,
the selected product must replace the product previously chosen.
Here is the code for my dropdownlist :
DropDownList drpProductList = new DropDownList();
drpProductList.DataSource = productCollection;
drpProductList.DataTextField = "Name";
drpProductList.DataValueField = "ProductID";
drpProductList.DataBind();
drpProductList.ID = "drpProductList" + product.ProductID.ToString();
drpProductList.SelectedIndexChanged += new EventHandler(this.drpProductList_SelectedIndexChanged);
drpProductList.AutoPostBack = true;
drpProductList.Attributes.Add("CommandArgument", product.ProductID.ToString());
headerCellDiv.Controls.Add(drpProductList);
Here is my drpProductList_SelectedIndexChanged function :
private void drpProductList_SelectedIndexChanged(object sender, EventArgs e)
{
//Supprimer le productID qui est dans le CommandArgument du controle de la comparelist
//pour y ajouter le product qu'on vient de sélectionner
DropDownList drp = (DropDownList)sender;
int productIDOld = Convert.ToInt32(drp.Attributes["CommandArgument"]);
int productIDNew = Convert.ToInt32(drp.SelectedValue);
Product productNew = ProductManager.GetByProductID(productIDNew);
ProductManager.RemoveProductFromCompareList(productIDOld);
//ProductCollection compareProducts = ProductManager.GetCompareProducts();
ProductManager.AddProductToCompareList(productIDNew);
//compareProducts = ProductManager.GetCompareProducts();
//int index = compareProducts.FindIndex(delegate(Product p) { return p.ProductID == productIDOld ; });
//compareProducts[index] = productNew;
Response.Redirect("~/CompareProducts.aspx");
}
Everything works fine, I have no error, but the result is like the line :
ProductManager.RemoveProductFromCompareList(productIDOld);
is totally ignored. The old product is never removed, however the execution in the function RemoveProductFromCompareList is OK.
It's like the cookie taken is the old one and not the new one.
I really don't know what to do.
Can you help me please?