Download presentation
Presentation is loading. Please wait.
Published byClinton Atkins Modified over 9 years ago
1
1 CS387/CS587: Note 08 Shopping Bag DataTable
2
2 DataClass Public Shared Function NewShoppingBag() As Data.DataTable Dim bag As New Data.DataTable bag.Columns.Add("Product ID") bag.Columns.Add("Product Name") bag.Columns.Add("Unit Price") bag.Columns.Add("Quantity") bag.Columns.Add("Sub-Total") Dim PK() As Data.DataColumn = {bag.Columns(0)} bag.PrimaryKey = PK Return bag End Function
3
3 Global.aspx Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started Dim bag As Data.DataTable bag = DataClass.NewShoppingBag() Session.Add("Bag", bag) ‘ same as Session("Bag“) = bag... End Sub One Bag for each Session
4
4 Save Button Protected Sub Button3_Click(...) Handles Button3.Click Dim bag As Data.DataTable bag = Session("Bag") Dim row, oldRow As Data.DataRow row = bag.NewRow row(0) = txtID.Text row(1) = txtName.Text... oldRow = bag.Rows.Find(txtID.Text) If Not oldRow Is Nothing Then bag.Rows.Remove(oldRow) End If bag.Rows.Add(row) Session("Bag") = bag End Sub
5
5 Checkout.aspx Protected Sub Page_Load(...) Handles Me.Load GridView1.DataSource = Session("Bag") GridView1.DataBind() End Sub
6
6 GridView Pages AllowPage: True PageSize: 5 BorderStyle: Double Caption: All Products CaptionAlign: Top PagerSettings: Visible: False (Use buttons)
7
7 GridView Pages Sub Session_Start(...)... Session("PageIndex“) = 0... End Sub
8
8 Page Default Protected Sub Page_Load(...) Handles Me.Load DataClass.getAllProducts() GridView1.DataSource = DataClass.tblProduct ‘ Set PageIndex before DataBind() GridView1.PageIndex = Session("PageIndex") GridView1.DataBind() ‘ Enable/disable buttons End Sub
9
9 Page Default Protected Sub Page_Load(...) Handles Me.Load DataClass.getAllProducts() If IsPostBack Then ‘ Let the events handle it Else GridView1.DataSource = DataClass.tblProduct ‘ Set PageIndex before DataBind() GridView1.PageIndex = Session("PageIndex") GridView1.DataBind() ‘ Enable/disable buttons End If End Sub
10
10 Page Next Protected Sub btnNext(...) Handles btnNext.Click ‘ Could be done in Form Load GridView1.DataSource = DataClass.tblProducts Session("PageIndex") += 1 GridView1.PageIndex = Session("PageIndex") GridView1.DataBind() ‘ Might be a good idea to create a Sub ManageButtons() End Sub
11
Lab 4 Grading You will lose five (5) points for each of the following: Updating does not work or causes a run time error Deleting does not work or causes a run time error Inserting does not work or causes a run time error Inserting an empty record causes a run time error Non-existing ID when shopping causes a run time error Invalid quantity when shopping causes a run time error Navigation buttons not enabled/disabled correctly or causes a run time error Any other run time error 11
12
Test 1 Tuesday, 50 Points Accessing Database Test1.accdb with two tables -10 for Each Run Time Error -10 for not updating database 12
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.