[.NET]請問 asp.net與 .net2003 做購物車
由於是初學者..所以還有很多地方不懂
懇請各位高手能夠指導ㄧ下..感謝~
目前只做到能夠讀取資料表..可以換頁
但要做選擇商品和數量加入購物袋時.遇到了問題
ㄧ是SqlConnection1型別未定義..是什麼意思呢..如何解決
二是Table1.Rows(I).Item("數量") = 1
並未將物件參考設定為物件的執行個體 ~ 這又如何解決呢?
這是參考書籍做的...
各位大大還有什麼方法可以做出購物車呢?
使用asp.net與 .net2003
謝謝
以下是商品選購程式碼
.............................................................................
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
DataSet11 = Session.Item("ds_Test")
Else
SqlConnection1.Open()
DA_tbTEST.Fill(DataSet11, "buy")
Session.Add("ds_Test", DataSet11)
SqlConnection1.Close()
DataGrid1.DataBind()
End If
If Not IsPostBack Then
Dim Hash As Hashtable
Dim ArrKey(Hash.Count - 1) As String
Dim ArrVal(Hash.Count - 1) As Integer
Dim Products As String
Hash.Keys.CopyTo(ArrKey, 0)
Hash.Values.CopyTo(ArrVal, 0)
Products = "('" & Join(ArrKey, "','") & "')"
Dim Provider = "Provider = Microsoft.Jet.OLEDB.4.0"""
Dim Ds As DataSet, SQL As String, I As Integer
Dim Database = "Data Source =" & Server.MapPath("TTT.mdb")
SqlConnection1 = New SqlConnection1(Provider & ";" & Database)
SqlConnection1.Open()
SQL = "Select * From 商品 Where 編號 In " & Products
DA_tbTEST = New SqlDataAdapter(SQL, SqlConnection1)
Ds = New DataSet
DA_tbTEST.Fill(Ds, "商品")
Dim Table1 As DataTable = Ds.Tables("商品")
Table1.Columns.Add(New DataColumn("購買", GetType(Boolean)))
Table1.Columns.Add(New DataColumn("數量", GetType(Integer)))
For I = 0 To Table1.Rows.Count - 1
Table1.Rows(I).Item("數量") = 1
Next
DataGrid1.DataSource = Table1.DefaultView
DataGrid1.DataBind()
End If
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.DataSource = CType(Session("DataView"), DataView)
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Hash As Hashtable, I As Integer
Dim cb As CheckBox = DataGrid1.Items(I).FindControl("BuyIt")
Dim lb As Label = DataGrid1.Items(I).FindControl("ProductID")
Dim tb As TextBox = DataGrid1.Items(I).FindControl("Quantity")
If Session("cbuy") Is Nothing Then
Hash = New Hashtable
Else
Hash = Session("cbuy")
End If
For I = 0 To DataGrid1.Items.Count - 1
If cb.Checked And Val(tb.Text) > 0 Then
If Not Hash.ContainsKey(lb.Text) Then
Hash.Add(lb.Text, CInt(Val(tb.Text)))
Else
Hash(lb.Text) += CInt(Val(tb.Text))
End If
End If
Next
Session("cbuy") = Hash
Response.Redirect("WebForm2.aspx")
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.171.141.74
推
10/18 10:32, , 1F
10/18 10:32, 1F
→
10/18 10:33, , 2F
10/18 10:33, 2F
→
10/18 10:34, , 3F
10/18 10:34, 3F
推
10/18 12:46, , 4F
10/18 12:46, 4F