2

I have a gridview which contains the details of a number of products. I'm trying to use simplecart (http://simplecartjs.com/) to add shopping cart functionality to my page, and am stuck on one thing. In order to add an item to the cart you have to use the following link, which I added to a column in the gridview:

<a href="javascript:;" onclick="simpleCart.add( 'name=Name' , 'price=123' , 'quantity=1' );">Add To Cart</a>

I want to pass the values in the ProductName column and ProductPrice column to name and price above for each row, but have no idea how to go about it. I am completely new to html/asp etc. so please forgive me if it is a simple question.

1 Answer 1

2

Assuming the product name and product price are in the data source you are binding to

onclick="simpleCart.add( 'name=<%# Eval("ProductName") %>' , 'price=<%# Eval("ProductPrice") %>' , 'quantity=1' );">Add To Cart</a>

(You could also use Bind rather than Eval - Bind is two way binding Eval is one way. In your case Eval is fine).

If the values aren't directly in the data source i.e need combining from two fields or need some complex formatting before display then you can use the RowDataBound event to squirt them into your anchor tag. The anchor tag will need to be a HTMLControl for this to work i.e. runat="server" - see http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx for details

Don't worry about simple questions, i can only provide simple answers!

Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfectly, thanks a lot! I'll try tinkering around with this RowDataBound event to see the different effects I can produce, thanks again for your help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.