Cart
-
I hv created cart dynamically at runtime through datatable............and i assigned it to the source of a datalist..............nw i want to edit quantity of products through datalist dynamically..........i tried many times.......but its not wrking properly.......this is my code.....
Dim dt As DataTable = Session("Cart") Dim dr As DataRow For i As Integer = 0 To DataList1.Items.Count - 1 Dim txt As Integer = CType(DataList1.Items(i).FindControl("txtQty"), TextBox).Text Dim hf As Integer = CType(DataList1.Items(i).FindControl("hfatc"), HiddenField).Value Dim val As Integer = Convert.ToInt32(txt) For Each dr In dt.Rows If dr("ItemNo") = hf Then dr("ItemQty") = val Session("Cart") = dt DataList1.DataSource = dt DataList1.DataBind() lblTtl.Text = "Rs." & GetItemTotal() End If Next Next
plz tell me.........where i m lacking behind.............is there any other way to do it......... plz guide me a bit.........:) -
I hv created cart dynamically at runtime through datatable............and i assigned it to the source of a datalist..............nw i want to edit quantity of products through datalist dynamically..........i tried many times.......but its not wrking properly.......this is my code.....
Dim dt As DataTable = Session("Cart") Dim dr As DataRow For i As Integer = 0 To DataList1.Items.Count - 1 Dim txt As Integer = CType(DataList1.Items(i).FindControl("txtQty"), TextBox).Text Dim hf As Integer = CType(DataList1.Items(i).FindControl("hfatc"), HiddenField).Value Dim val As Integer = Convert.ToInt32(txt) For Each dr In dt.Rows If dr("ItemNo") = hf Then dr("ItemQty") = val Session("Cart") = dt DataList1.DataSource = dt DataList1.DataBind() lblTtl.Text = "Rs." & GetItemTotal() End If Next Next
plz tell me.........where i m lacking behind.............is there any other way to do it......... plz guide me a bit.........:)KhandelwalA wrote:
Dim dt As DataTable = Session("Cart")
Putting a datatable into the session seems wasteful to me.
KhandelwalA wrote:
For i As Integer = 0 To DataList1.Items.Count - 1
Does this work ? In C# it would miss the last item.
KhandelwalA wrote:
Session("Cart") = dt
Every time ? Why on earth are you doing this inside the loop ?
KhandelwalA wrote:
DataList1.DataSource = dt DataList1.DataBind()
Wow - again, this is very wasteful.
KhandelwalA wrote:
is there any other way to do it.........
There's much better ways to do this. How about storing an id in the session and storing the cart in the database ? Then you could modify the cart with SQL, for a start.
KhandelwalA wrote:
Dim txt As Integer = CType(DataList1.Items(i).FindControl("txtQty"), TextBox).Text
KhandelwalA wrote:
Dim val As Integer = Convert.ToInt32(txt)
What are you writing this for ? Is it actually going to be used for anything ? By whom ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.