I need to create a button to remove a single line from the basket. Right now, I'm using a LinkButton that use javascript to put the quantity field to zero and then do his postback. It works fine but if the client do not have javascript active on his browser, it will not work... So my question is, does a better solution exist without using javascript I searched for a removeItem fonction but found nothing.


Re: Commerce Server 2007 Creating a button to remove a single product from the basket.

Jeff Lynch - MVP

I use a GridView control to display the Basket to site users. I have a command field on each row of the GridView used to actually delete the item. I have created an event handler which is called from the GridView's "OnRowDeleting" event. The event handler uses the GridViewDeleteEventArgs.RowIndex property which corresponds to the Basket's LineItem.Index property so the method knows which LineItem to delete. This event handler calls a helper class which does the actual work using the code shown below.

public void RemoveBasketItem(int Index)
// Remove the LineItem from the Basket using it's index

// Update and save the Basket

public void UpdateBasket(string pipelinename)
// Dispose of the PipelineInfo object since it references COM objects
using (PipelineInfo info = new PipelineInfo(pipelinename))
if (CommerceContext.Current.UserProfile != null)
// Add the UserObject to the Discount's TargetingProfileCollection
info.Profiles.Add("UserObject", CommerceContext.Current.UserProfile);

// Run the pipeline

// Save the Basket

Setting the LineItem.Quantity property to zero doesn't delete the LineItem.

Ping me if you'd like a sample of the code to look over. Just remove the [nospam] from the email address.

Jeff Lynch

MVP Windows Server System - Commerce Server


Re: Commerce Server 2007 Creating a button to remove a single product from the basket.



Is it possible for you to email me your Javascript code - I am trying to put in similiar functionality and do not want to put everything into a grid.

Email address obviouly with the [nospam] removed ccnautical@[nospam]

Thank You.