Page 1 of 2 12 LastLast
Results 1 to 40 of 43

Thread: Updating txtQuantity in a Repeater

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Updating txtQuantity in a Repeater

    I created a repeater to list my data inside a dataTable of Session("Cart")
    however i have a problem. I cannot seem to update the Quantity.
    How do i code a 'btnUpdate' so that it will read the txtQuantity and update
    each row of item's quantity according to the txtQuantity.Text?

    <asp:Repeater id="viewCart" runat="server">
    <ItemTemplate>
    <tr>
    <td height="15"><%# Container.DataItem("Product") %></td>
    td><%# Container.DataItem("Code") %></td>
    <td><%# Double.Parse(Container.DataItem("Cost")).ToString("C") %></td>
    <td align="center"><asp:TextBox ID="txtQuantity" Text='<%# Container.DataItem("Quantity") %>' ToolTip="Quantity" Width="20" MaxLength="2" runat="server" /></td>
    <td>Remove</td>
    </tr>
    </ItemTemplate>
    </asp:Repeater>

    Header Codes:

    Dim dtCart As DataTable
    Dim drCart As DataRow
    dtCart = Session("Cart")
    viewCart.DataSource = dtCart.DefaultView
    viewCart.DataBind()

    -

    How can i delete that row too?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    You want to loop through the textboxes right?

    Here's a sample of me looping through the items in the repeater, looking for a checkbox. You can modify it according to your needs to assign a value to your textboxes.

    VB Code:
    1. For Each rItem In Me.rptDepts.Items
    2.  
    3.  
    4.  
    5.             If rItem.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
    6.                 Dim chkB As New CheckBox
    7.                 chkB = CType(rItem.FindControl("chkDepartment"), CheckBox)
    8.                 If chkB.Checked = True Then
    9.                     'update it here
    10.                 End If
    11.  
    12.  
    13.             End If
    14.  
    15.         Next

    rItem is declared as a RepeaterItem

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    thanks, in my below case, i tried, it doesnt work.

    <script runat="server">
    Sub updateQuantity(sender as Object, e As EventArgs)
    For Each viewCart In Me.viewCart.Items
    If viewCart.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
    Dim txtbox As New TextBox
    txtbox = CType(viewCart.FindControl("txtQuantity"), TextBox)
    If txtbox.Text <> "" Then
    txtQuantity.Text = txtbox.Text
    End If
    End If
    Next
    End Sub
    </script>

    HTML BODY

    <asp:Repeater id="viewCart" runat="server">
    <ItemTemplate>
    <tr>
    <td><%# Container.DataItem("Product") %></td>
    <td><%# Container.DataItem("Code") %></td>
    <td><%# Double.Parse(Container.DataItem("Cost")).ToString("C") %></td>
    <td align="center"><asp:TextBox ID="txtQuantity" Text='<%# Container.DataItem("Quantity") %>' ToolTip="Quantity" Width="20" MaxLength="2" runat="server" /></td>
    <td align="center">Remove</td>
    </tr>
    <tr><td colspan="5"><hr size="1"></td></tr>
    </ItemTemplate>
    </asp:Repeater>

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    ??

    For Each viewCart In Me.viewCart.Items

    That's quite a paradox.

    Look at what I wrote:

    For Each rItem In Me.rptDepts.Items

    The first variable must be declared as a RepeaterItem. I don't see where you've declared the variable.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    thanks i tried, is the below correct? theres an error saying txtQuantity is not declared, however i have a asp:Textbox id="txtQuantity".

    Sub updateCart(sender As Object, e As ImageClickEventArgs)

    Dim rItem As RepeaterItem

    For Each rItem In Me.viewCart.Items
    If rItem.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
    Dim txtBox As New TextBox
    txtBox = CType(rItem.FindControl("txtQuantity"), TextBox)
    If txtBox.Text <> "" Then
    txtQuantity.Text = txtBox.Text
    End If


    End If
    Next


    Error MSG:
    Compiler Error Message: BC30451: Name 'txtQuantity' is not declared.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    What is this line:

    Code:
     txtQuantity.Text = txtBox.Text
    Supposed to do?

    Note that txtBox is basically the current row's txtQuantity textbox, you already have it.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    i'm confused, i thot thats to update the textbox?

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    What do you want to update each of those textboxes with? Where is that value stored?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    in txtQuantity textbox inside this repeating

    <asp:Repeater id="viewCart" runat="server">
    <ItemTemplate>
    <tr>
    <td height="15"><%# Container.DataItem("Product") %></td>
    td><%# Container.DataItem("Code") %></td>
    <td><%# Double.Parse(Container.DataItem("Cost")).ToString("C") %></td>
    <td align="center"><asp:TextBox ID="txtQuantity" Text='<%# Container.DataItem("Quantity") %>' ToolTip="Quantity" Width="20" MaxLength="2" runat="server" /></td>
    <td>Remove</td>
    </tr>
    </ItemTemplate>
    </asp:Repeater>

    Header Codes:

    Dim dtCart As DataTable
    Dim drCart As DataRow
    dtCart = Session("Cart")
    viewCart.DataSource = dtCart.DefaultView
    viewCart.DataBind()

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    Dude, what do you want to update that textbox with?

  11. #11

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    sorry for not being clear, the repeater will display the product name, code
    cost and quantity. The quantity is in a Textbox, editable by the user. Therefore
    each product has a Textbox (txtQuantity) in the repeater. Therefore user can
    edit the Quantity in the textbox and when click 'update'. The values of this
    textbox txtQuantity will be updated to what the user keyed in 1-99 value.

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    I don't think that still makes any sense. Because the user will key in the value into the textbox. You have to decide the next step, what occurs next when they click update. Is it just a postback of the page, or do you save the values somewhere (to a database) and then redirect to another page?

  13. #13

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    oh ok, it should postback the page and update the textbox of the new Quantity value previously entered in the same textbox inside the repeater loop. its like refreshing the same page, but only difference is editing the values of the Quantity textboxes..

    Is it clear this way?

  14. #14

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    been trying for hours doesnt work

  15. #15

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    anyone can help?

  16. #16

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    no one can help?

  17. #17

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    anyone?

  18. #18

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    i tried looking up repeateritem control, doesnt seem to have anything.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    anyone can help?

  20. #20
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    Quote Originally Posted by john83
    oh ok, it should postback the page and update the textbox of the new Quantity value previously entered in the same textbox inside the repeater loop. its like refreshing the same page, but only difference is editing the values of the Quantity textboxes..

    Is it clear this way?
    It isn't, sorry.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    with the code below, i have a textbox txtQuantity that is repeated in
    a datatable Session("Cart") that has 4 rows example. Therefore i have
    4 x textboxes of txtQuantity right? each of them represent a field value
    of 'Quantity' referenced to each 'quantity' of of the data table, how do i
    code the update button to loop through the repeater textbox item and
    have it update the datatable.

    DataTable columns: Product, Code, Cost, Quantity

    <asp:Repeater id="viewCart" runat="server">
    <ItemTemplate>
    <tr>
    <td height="15"><%# Container.DataItem("Product") %></td>
    td><%# Container.DataItem("Code") %></td>
    <td><%# Double.Parse(Container.DataItem("Cost")).ToString("C") %></td>
    <td align="center"><asp:TextBox ID="txtQuantity" Text='<%# Container.DataItem("Quantity") %>' ToolTip="Quantity" Width="20" MaxLength="2" runat="server" /></td>
    <td>Remove</td>
    </tr>
    </ItemTemplate>
    </asp:Repeater>

    Header Codes:

    Dim dtCart As DataTable
    Dim drCart As DataRow
    dtCart = Session("Cart")
    viewCart.DataSource = dtCart.DefaultView
    viewCart.DataBind()
    Last edited by john83; May 22nd, 2005 at 08:34 AM.

  22. #22
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    Is that what you wanted?? Then why didn't you just say so?

    OK, in the loop that you've got above, you must place an intCounter (of type... integer), which you increment in each loop. When you reach a txtQuantity box, set the value in your datatable to the value in the textbox.

    I do not have the IDE open but I'm sure you know how to access the value in your datatable. It might be something like this:

    dt.Rows(intCounter)("Quantity") = Integer.Parse(txtQuantity.Text)

  23. #23

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    yep thats what i wanted. where do i put that line in.
    my question will be how do i code my btnUpdate procedure?

  24. #24
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    In your loop! Right after the itemtype confirms, increment the counter. Just place the code in the btnUpdate click event.

  25. #25

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    thanks its getting clearer for me, however i got an error saying txtQuantity is not declared. How can this be so, as it is in the repeateritem loop?

    I tried to change it to, but it still doesnt work, can u check my codes?

    Dim rItem As RepeaterItem
    Dim intCounter As Integer
    Dim dt As DataTable
    dt = Session("Cart")
    For Each rItem In Me.Cart.Items 'Cart is the repeater id & datatable
    If rItem.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
    dt.Rows(intCounter)("Quantity") = Integer.Parse(Request.Form("txtQuantity")) 'since txtQuantity.Text gives error.
    intCounter += 1
    End If
    Next
    Session("Cart") = dt
    End Sub
    Last edited by john83; May 23rd, 2005 at 12:23 PM.

  26. #26
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    Use it in the loop above, so you'd assign the value in txtBox.Text. Not txtQuantity.

  27. #27

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    I tried the below codes myself, but it doesnt seem to work. theres
    an error below. Please advise!

    <asp:Repeater id="viewCart" runat="server">
    <ItemTemplate>
    <tr>
    <td height="15"><%# Container.DataItem("Product") %></td>
    td><%# Container.DataItem("Code") %></td>
    <td><%# Double.Parse(Container.DataItem("Cost")).ToString("C") %></td>
    <td align="center"><asp:TextBox ID='txtQuantity_<%# Container.DataItem("Code") %>' Text='<%# Container.DataItem("Quantity") %>' ToolTip="Quantity" Width="20" MaxLength="2" runat="server" /></td>
    <td>Remove</td>
    </tr>
    </ItemTemplate>
    </asp:Repeater>

    Header Codes:

    Dim dtCart As DataTable
    Dim drCart As DataRow
    dtCart = Session("Cart")

    dtCart = Session("Cart")
    For Each rItem In Me.viewCart.Items
    If rItem.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
    dtCart.Rows(intCount)("Quantity") = Integer.Parse(txtQuantity_(dtCart.Rows(intCount)("Code")).Text)
    intCount += 1
    End If
    Next
    Session("Cart") = dtCart

    viewCart.DataSource = dtCart.DefaultView
    viewCart.DataBind()
    -

    Error:
    'txtQuantity_<%# Container.DataItem("Code") %>' is not a valid identifier.
    Last edited by john83; May 23rd, 2005 at 09:25 PM.

  28. #28
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    For Each rItem In Me.viewCart.Items
    If rItem.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
    Dim txtBox As New TextBox
    txtBox = CType(rItem.FindControl("txtQuantity"), TextBox)
    If txtBox.Text <> "" Then
    dtCart.Rows(intCount)("Quantity") = Integer.Parse(txtBox.Text)
    End If

  29. #29

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    Thanks, still doesnt work. the values go back to the old ones after i click update. Heres my code.


    <script runat="server">
    Sub updateCart(sender As Object, e As ImageClickEventArgs)
    Dim rItem As RepeaterItem
    Dim intCount As Integer
    Dim dtCart As DataTable
    dtCart = Session("Cart")
    For Each rItem In Me.viewCart.Items
    If rItem.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
    Dim txtBox As New TextBox
    txtBox = CType(rItem.FindControl("txtQuantity"), TextBox)
    If txtBox.Text <> "" Then
    dtCart.Rows(intCount)("Quantity") = Integer.Parse(txtBox.Text)
    End If
    End If
    Next
    Session("Cart") = dtCart
    End Sub
    </script>

    <asp:Repeater id="viewCart" runat="server">
    <ItemTemplate>
    <tr>
    <td><%# Container.DataItem("Product") %></td>
    <td><%# Container.DataItem("Code") %></td>
    <td><%# Double.Parse(Container.DataItem("Cost")).ToString("C") %></td>
    <td align="center"><asp:TextBox id="txtQuantity" Text='<%# Container.DataItem("Quantity") %>' ToolTip="Quantity" Width="20" MaxLength="2" runat="server" /></td>
    <td align="center">Remove</td>
    </tr>
    <tr><td colspan="5"><hr size="1"></td></tr>
    </ItemTemplate>
    </asp:Repeater>

    <asp:ImageButton ID="btnUpdate" AlternateText="Update Cart" ImageUrl="images/updatecart.gif" ToolTip="Update Cart" OnClick="updateCart" runat="server" />

  30. #30
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    Step through the code and see if the textbox contains the new values.

  31. #31

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    weird it doesnt

  32. #32
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    Set EnableViewState = "true" for the textbox control in the repeater.

  33. #33

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    tried txtBox.EnableViewState = True
    still same! sorry abt this.

    is there anyway i can show u, hmm trace or anything?

  34. #34
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Updating txtQuantity in a Repeater

    Attach your aspx and aspx.vb to this thread.. so we can download and look at it. Christ Mendhak your patient !

  35. #35
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    I did have to take a small break in between

  36. #36

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    attached. please let me know where i went wrong.
    Attached Files Attached Files

  37. #37
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    You're using Visual Studio?

  38. #38

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    using Dreamweaver MX and manually coding the VB codes.

  39. #39

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Re: Updating txtQuantity in a Repeater

    how is it?

  40. #40
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Updating txtQuantity in a Repeater

    Not good. This'll take some time to 'understand'

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width