The drag function has already become a highlight of attracting users from various websites. Have you ever wondered how to apply the drag function to the shopping cart function module of e-commerce websites? In this way, the buyer only needs to drag the item he or she is interested in to his or her own shopping cart. He or she can also delete the item from the shopping cart and update the overall price and quantity of the shopping cart.
Let's start with the instance. This instance does not connect to the database to read data to initialize Products. Instead, it creates some virtual Products as follows:
1. Create a Product entity class
The Code is as follows:
Public class Product
{
Public string Code {get; set ;}
Public string Name {get; set ;}
Public string Description {get; set ;}
Public double Price {get; set ;}
}
[Code]
2. Create a product List
[Code]
Public class Product
{
Public string Code {get; set ;}
Public string Name {get; set ;}
Public string Description {get; set ;}
Public double Price {get; set ;}
}
3. Create a DataList and bind the List
The Code is as follows:
RepeatDirection = "Horizontal" runat = "server">
Code = '<% # Eval ("Code") %>' id = 'item _ <%# Container. ItemIndex + 1%> '>
<% # Eval ("Code") %>
<% # Eval ("Name") %>
<% # Eval ("Description") %>
$ <% # Eval ("Price") %>
Private void BindData ()
{
Var products = GetProducts ();
DlProducts. DataSource = products;
DlProducts. DataBind ();
}
ProductItemStyle style name
Container. ItemIndex dynamically generates consecutive item numbers
4. Generate Products Div Draggable
Download the latest Jquery JS file and Its UI file:
The Code is as follows: