Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Cart

Cart

Scheduled Pinned Locked Moved ASP.NET
tutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KhandelwalA
    wrote on last edited by
    #1

    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.........:)

    C 1 Reply Last reply
    0
    • K KhandelwalA

      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.........:)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups