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?
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:
For Each rItem In Me.rptDepts.Items
If rItem.ItemType = ListItemType.AlternatingItem OrElse rItem.ItemType = ListItemType.Item Then
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>
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.
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.
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?
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..
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..
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.
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:
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.
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
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
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>