![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Creating a Simple Shopping Cart Application
Số trang: 6
Loại file: pdf
Dung lượng: 40.16 KB
Lượt xem: 12
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Creating a Simple Shopping Cart Application In this section, youll modify your DataGridWebApplication you created earlier to turn it into a simple shopping cart.
Nội dung trích xuất từ tài liệu:
Creating a Simple Shopping Cart ApplicationCreating a Simple Shopping Cart ApplicationIn this section, youll modify your DataGridWebApplication you created earlier to turn itinto a simple shopping cart. Youll store the shopping cart in a Session object.Note As mentioned in the previous section, in a real application youll probably want to store the shopping cart in the database rather than in a Session object.Figure 15.24 shows the final running form that youll build. You use the Buy button toadd a product to the shopping cart shown on the right of the form. As you can see fromFigure 15.24, Ive added three products to the shopping cart by pressing the Buy buttonfor each product in the grid on the left.Figure 15.24: The running formYou can either follow the steps shown in the following sections to add the Buy buttonand the shopping cart to your form, or you can replace the ASP.NET code in your formwith the code in the WebForm1.aspx file contained in the VS .NETProjectsDataGridWebApplication directory. You replace the code in your form byselecting and deleting the existing code in your form and pasting in the code from theWebForm1.aspx file. Youll also need to replace the code behind your form with the codein the WebForm1.aspx.cs file contained in the VS .NETProjectsDataGridWebApplication directory.Adding the Buy ButtonIn this section, youll add the Buy button to the DataGrid1 object of theDataGridWebApplication. Perform the following steps:1. Open DataGridWebApplication by selecting File ➣ Open ➣ Project, double-click the Data-GridWebApplication folder, and double-click the DataGridWebApplication.sln file.2. Open the WebForm1.aspx file in Design mode by double-clicking this file in the Solution Explorer window. Click on the DataGrid1 control in the form. Figure 15.25 shows the properties for DataGrid1. Figure 15.25: DataGrid1 properties3. Next, click the Property Builder link near the bottom of the Properties window. Do the following to add the Buy button: 1. Click Columns on the left of the DataGrid1 Properties dialog box. 2. Expand the Button Column node of the Available Columns section. 3. Add a Select button to the Selected Columns area. 4. Set Text to Buy. This is the text that is shown on the button. 5. Set Command Name to AddToCart. This is the method that is called when the button is pressed. (Youll create this method later.) 6. Set Button Type to PushButton. Figure 15.26 shows the final properties of the Buy button. Figure 15.26: Buy button properties 4. Click OK to add the button to DataGrid1. Figure 15.27 shows DataGrid1 with the newly added Buy button. Figure 15.27: DataGrid1 with Buy buttonAdding the Shopping CartIn this section, youll add a DataGrid to store the shopping cart. Drag a DataGrid controlfrom the Toolbox to the right of DataGrid1 on your form. Set the ID of this new DataGridto ShoppingCart, as shown in Figure 15.28.Figure 15.28: ShoppingCart DataGridNote You might have to close all windows except the form designer so that you have enough screen space to add the new DataGrid to your form.Adding Code to the WebForm1.aspx.cs FileYour next task is to add some additional code to the WebForm1.aspx.cs file to supportthe shopping cart. As mentioned earlier, either you can follow the steps shown in thissection or you can replace the code behind your form with the code in theWebForm1.aspx.cs file contained in the VS .NET ProjectsDataGridWebApplicationdirectory. You replace the code in your form by selecting and deleting the existing codein your form and pasting in the code from the WebForm1.aspx.cs file.Perform the following steps if you want to modify the code yourself: 1. Select View ➣ Code, or press F7 on your keyboard to view the code. Add a DataTable object named Cart and a DataView object named CartView to the WebForm1 class, as shown in the following code: 2. public class WebForm1 : System.Web.UI.Page 3. { 4. protected DataTable Cart; 5. protected DataView CartView; 6. Your Cart object is used to store the shopping cart and will be populated with the products selected using the Buy button. Your CartView object is used to view the shopping cart. 7. Next, set your Page_Load() method to the following code; notice that this method creates a DataTable to store the shopping cart, and that this DataTable is stored in the Session object:8. private void Page_Load(object sender, System.EventArgs e)9. {10. // Put user code to initialize the page here11.12. // populate the Session object with the shopping cart13. if (Session[ShoppingCart] == null)14. {15. Cart = new DataTable();16. Cart.Columns.Add(new DataColumn(Product Name, typeof(string)));17. Cart.Columns.Add(new DataColumn(Unit Price, typ ...
Nội dung trích xuất từ tài liệu:
Creating a Simple Shopping Cart ApplicationCreating a Simple Shopping Cart ApplicationIn this section, youll modify your DataGridWebApplication you created earlier to turn itinto a simple shopping cart. Youll store the shopping cart in a Session object.Note As mentioned in the previous section, in a real application youll probably want to store the shopping cart in the database rather than in a Session object.Figure 15.24 shows the final running form that youll build. You use the Buy button toadd a product to the shopping cart shown on the right of the form. As you can see fromFigure 15.24, Ive added three products to the shopping cart by pressing the Buy buttonfor each product in the grid on the left.Figure 15.24: The running formYou can either follow the steps shown in the following sections to add the Buy buttonand the shopping cart to your form, or you can replace the ASP.NET code in your formwith the code in the WebForm1.aspx file contained in the VS .NETProjectsDataGridWebApplication directory. You replace the code in your form byselecting and deleting the existing code in your form and pasting in the code from theWebForm1.aspx file. Youll also need to replace the code behind your form with the codein the WebForm1.aspx.cs file contained in the VS .NETProjectsDataGridWebApplication directory.Adding the Buy ButtonIn this section, youll add the Buy button to the DataGrid1 object of theDataGridWebApplication. Perform the following steps:1. Open DataGridWebApplication by selecting File ➣ Open ➣ Project, double-click the Data-GridWebApplication folder, and double-click the DataGridWebApplication.sln file.2. Open the WebForm1.aspx file in Design mode by double-clicking this file in the Solution Explorer window. Click on the DataGrid1 control in the form. Figure 15.25 shows the properties for DataGrid1. Figure 15.25: DataGrid1 properties3. Next, click the Property Builder link near the bottom of the Properties window. Do the following to add the Buy button: 1. Click Columns on the left of the DataGrid1 Properties dialog box. 2. Expand the Button Column node of the Available Columns section. 3. Add a Select button to the Selected Columns area. 4. Set Text to Buy. This is the text that is shown on the button. 5. Set Command Name to AddToCart. This is the method that is called when the button is pressed. (Youll create this method later.) 6. Set Button Type to PushButton. Figure 15.26 shows the final properties of the Buy button. Figure 15.26: Buy button properties 4. Click OK to add the button to DataGrid1. Figure 15.27 shows DataGrid1 with the newly added Buy button. Figure 15.27: DataGrid1 with Buy buttonAdding the Shopping CartIn this section, youll add a DataGrid to store the shopping cart. Drag a DataGrid controlfrom the Toolbox to the right of DataGrid1 on your form. Set the ID of this new DataGridto ShoppingCart, as shown in Figure 15.28.Figure 15.28: ShoppingCart DataGridNote You might have to close all windows except the form designer so that you have enough screen space to add the new DataGrid to your form.Adding Code to the WebForm1.aspx.cs FileYour next task is to add some additional code to the WebForm1.aspx.cs file to supportthe shopping cart. As mentioned earlier, either you can follow the steps shown in thissection or you can replace the code behind your form with the code in theWebForm1.aspx.cs file contained in the VS .NET ProjectsDataGridWebApplicationdirectory. You replace the code in your form by selecting and deleting the existing codein your form and pasting in the code from the WebForm1.aspx.cs file.Perform the following steps if you want to modify the code yourself: 1. Select View ➣ Code, or press F7 on your keyboard to view the code. Add a DataTable object named Cart and a DataView object named CartView to the WebForm1 class, as shown in the following code: 2. public class WebForm1 : System.Web.UI.Page 3. { 4. protected DataTable Cart; 5. protected DataView CartView; 6. Your Cart object is used to store the shopping cart and will be populated with the products selected using the Buy button. Your CartView object is used to view the shopping cart. 7. Next, set your Page_Load() method to the following code; notice that this method creates a DataTable to store the shopping cart, and that this DataTable is stored in the Session object:8. private void Page_Load(object sender, System.EventArgs e)9. {10. // Put user code to initialize the page here11.12. // populate the Session object with the shopping cart13. if (Session[ShoppingCart] == null)14. {15. Cart = new DataTable();16. Cart.Columns.Add(new DataColumn(Product Name, typeof(string)));17. Cart.Columns.Add(new DataColumn(Unit Price, typ ...
Tìm kiếm theo từ khóa liên quan:
kĩ thuật lập trình công nghệ thông tin lập trình ngôn ngữ lập trình C Shark C# sybex - c.sharp database programming Creating a Simple Shopping Cart ApplicationTài liệu liên quan:
-
52 trang 439 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 329 0 0 -
74 trang 309 0 0
-
96 trang 305 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 299 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 291 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 291 1 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 282 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 279 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 278 0 0