isaacab
asked on
ASP Repeater - Shopping cart quantity problem
My question is as follows:
The repeater what attached here it works well. The only problem is that I need to identify what is the “Quantity” value in each row.
When I need to identify a value from the repeater (SqlDataReader) I use the “<%#DataBinder.Eval(Contai ner.DataIt em, "SomeField")%>“,
But which syntax I could use to identify a field like “quantity” what is not a part of the SqlDataReader?
Attention please: <a id="btnAdd" href=”UpdateCart.aspx?Prod uctID=<%#D ataBinder. Eval(Conta iner.DataI tem, "ProductID")%>”
The source ASP code as follows:
***Begin***
<asp:repeater id="Items" Runat="server">
<ItemTemplate>
<tr bgcolor="#eeeeee">
<td class="Listing"><%#DataBin der.Eval(C ontainer.D ataItem, "Description")%></td>
<td class="Listing"><strong><% #DataBinde r.Eval
(Container.DataItem, "DayPrice","{0:C2}")%></st rong></td>
<td class="Listing"><font color="#666666"><%#DataBin der.Eval(C ontainer.D ataItem, "WeekPrice","{0:C2}")%></f ont></td>
<td>
<div align="center">
<asp:textbox ID="Quantity" size="3" Runat="server">1</asp:text box>
</div>
</td>
<td>
<div align="right"><asp:imageBu tton id="AddToCart" runet="server" OnClick="<%# AddToMyCart(DataBinder.Eva l(Containe r.DataItem , "ProductID"),DataBinder.Ev al(Contain er.DataIte m, "ShoppingCartID"),DataBind er.Eval(Co ntainer.Da taItem, "Quantity"))"
/></div></td></tr>
</ItemTemplate>
</asp:repeater>
***End***
Now, I have in the VB code behind a sub what his job is to append it to the shopping cart, and it also works well.
So again, how i get access to the current "Quantity" TextBox?
Thanks for your time.
The repeater what attached here it works well. The only problem is that I need to identify what is the “Quantity” value in each row.
When I need to identify a value from the repeater (SqlDataReader) I use the “<%#DataBinder.Eval(Contai
But which syntax I could use to identify a field like “quantity” what is not a part of the SqlDataReader?
Attention please: <a id="btnAdd" href=”UpdateCart.aspx?Prod
The source ASP code as follows:
***Begin***
<asp:repeater id="Items" Runat="server">
<ItemTemplate>
<tr bgcolor="#eeeeee">
<td class="Listing"><%#DataBin
<td class="Listing"><strong><%
(Container.DataItem, "DayPrice","{0:C2}")%></st
<td class="Listing"><font color="#666666"><%#DataBin
<td>
<div align="center">
<asp:textbox ID="Quantity" size="3" Runat="server">1</asp:text
</div>
</td>
<td>
<div align="right"><asp:imageBu
/></div></td></tr>
</ItemTemplate>
</asp:repeater>
***End***
Now, I have in the VB code behind a sub what his job is to append it to the shopping cart, and it also works well.
So again, how i get access to the current "Quantity" TextBox?
Thanks for your time.
ASKER
Thanks for your time,
My question was, How to "SET" from a repeater to a DB table, but not how to "GET".
Any ideas?
My question was, How to "SET" from a repeater to a DB table, but not how to "GET".
Any ideas?
oh, i see. You could just put a text box in the repeater and have a link that takes the value from the text box and updates the page.
ASKER
Thanks,
This exactly is my question, How to take the value from the "current" repeat line? How to take the "current" Product ID i know (<%#DataBinder.Eval(Contai
Please help. thanks again.
HI isaacab,
for the your question the answer - you can not do this directly. This is because Container.DataItem is connected with the current datasource property of the reperater control. You can easily to use the ItemDataBound event of the reperater control and there based of the productId value to get the quantity from another query.
Another way of make this working is to modify your sql query to return and quanity in the same repeater.
If you have any problems with programing of one of the scenarious above, please let me know
Regards
mmarinov
for the your question the answer - you can not do this directly. This is because Container.DataItem is connected with the current datasource property of the reperater control. You can easily to use the ItemDataBound event of the reperater control and there based of the productId value to get the quantity from another query.
Another way of make this working is to modify your sql query to return and quanity in the same repeater.
If you have any problems with programing of one of the scenarious above, please let me know
Regards
mmarinov
ASKER
Thanks mmarinov,
My problem is not how to GET the quantity value from my DataSource. that's i know. The problem is, how to UPDATE the quantity value in my DataSource when the quantity text-box is NOT a part of the dataSource. That's mean, when a customer will change the quantity and he will clicks on the "Add to cart" button, How i take the new quantity value what the customer put in, and put it in my dataSource table?
Please help. Thanks again.
My problem is not how to GET the quantity value from my DataSource. that's i know. The problem is, how to UPDATE the quantity value in my DataSource when the quantity text-box is NOT a part of the dataSource. That's mean, when a customer will change the quantity and he will clicks on the "Add to cart" button, How i take the new quantity value what the customer put in, and put it in my dataSource table?
Please help. Thanks again.
HI isaacab,
I think i understand your question now. So i suggeest you to use ItemCommand event of the Repeater control and add to your ImageButton control CommandName="AddToCart".
So the code can be something like this:
<asp:repeater id="Items" Runat="server" OnItemCommand="Items_ItemC ommand">
<ItemTemplate>
<tr bgcolor="#eeeeee">
<td class="Listing"><%#DataBin der.Eval(C ontainer.D ataItem, "Description")%></td>
<td class="Listing"><strong><% #DataBinde r.Eval
(Container.DataItem, "DayPrice","{0:C2}")%></st rong></td>
<td class="Listing"><font color="#666666"><%#DataBin der.Eval(C ontainer.D ataItem, "WeekPrice","{0:C2}")%></f ont></td>
<td>
<div align="center">
<asp:textbox ID="Quantity" size="3" Runat="server">1</asp:text box>
</div>
</td>
<td>
<div align="right"><asp:imageBu tton id="AddToCart" runet="server" CommandName="AddToCart"/>< /div></td> </tr>
</ItemTemplate>
</asp:repeater>
c#
------------------
void Items_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
{
if(e.CommandName == "AddToCart")
{
TextBox quantityTextBox = (TextBox)e.Item.FindContro l("Quantit y");
//to get the content of the new quantity you can use quantityTextBox.Text
//and call your method AddToMyCart
}
}
vb.net
-------------------
Sub Items_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs)
if e.CommandName = "AddToCart" Then
Dim quantityTextBox as TextBox = CType(e.Item.FindControl(" Quantity") , TextBox)
'to get the content of the new quantity you can use quantityTextBox.Text
'and call your method AddToMyCart
End If
End Sub
Hope This Helps
Regards
mmarinov
I think i understand your question now. So i suggeest you to use ItemCommand event of the Repeater control and add to your ImageButton control CommandName="AddToCart".
So the code can be something like this:
<asp:repeater id="Items" Runat="server" OnItemCommand="Items_ItemC
<ItemTemplate>
<tr bgcolor="#eeeeee">
<td class="Listing"><%#DataBin
<td class="Listing"><strong><%
(Container.DataItem, "DayPrice","{0:C2}")%></st
<td class="Listing"><font color="#666666"><%#DataBin
<td>
<div align="center">
<asp:textbox ID="Quantity" size="3" Runat="server">1</asp:text
</div>
</td>
<td>
<div align="right"><asp:imageBu
</ItemTemplate>
</asp:repeater>
c#
------------------
void Items_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
{
if(e.CommandName == "AddToCart")
{
TextBox quantityTextBox = (TextBox)e.Item.FindContro
//to get the content of the new quantity you can use quantityTextBox.Text
//and call your method AddToMyCart
}
}
vb.net
-------------------
Sub Items_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs)
if e.CommandName = "AddToCart" Then
Dim quantityTextBox as TextBox = CType(e.Item.FindControl("
'to get the content of the new quantity you can use quantityTextBox.Text
'and call your method AddToMyCart
End If
End Sub
Hope This Helps
Regards
mmarinov
ASKER
Thanks a lot mmarinov for your time,
This actually works fine, but...
Your solution works only if i have a ADD TO CART button on every item in my repeater, but i have only 1 ADD TO CART button in the bottom of my page. So, when the user will clicks on the ADD TO CART button, i need to loop thru all the items in my repeater, and i cannot do it, because i cannot send the "RepeaterCommandEventArgs" from the ImageButton.
Do you have a solution for this?
Please help. Thanks in advance.
This actually works fine, but...
Your solution works only if i have a ADD TO CART button on every item in my repeater, but i have only 1 ADD TO CART button in the bottom of my page. So, when the user will clicks on the ADD TO CART button, i need to loop thru all the items in my repeater, and i cannot do it, because i cannot send the "RepeaterCommandEventArgs"
Do you have a solution for this?
Please help. Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot Martin, It works now wery well.
You help me a lot. Of course is the 500 points for you.
Thanks Isaacab,
Glad to help
Regards
mmarinov
Glad to help
Regards
mmarinov
ASKER
Sorry Martin for bother you,
Do you have an idea if i would like to have a button on EVERY item, but instead a ImageButton i want put an HTML anchor.
So, what i have to write instead CommandName="AddToCart"? the HTML don't have the CommandName property.
Thanks in advance.
Do you have an idea if i would like to have a button on EVERY item, but instead a ImageButton i want put an HTML anchor.
So, what i have to write instead CommandName="AddToCart"? the HTML don't have the CommandName property.
Thanks in advance.
Hi isaacab ,
Why do you want to do that? May be if you post the reason for this requirement - it will be much easier to find a solution.
Regards
mmarinov
Why do you want to do that? May be if you post the reason for this requirement - it will be much easier to find a solution.
Regards
mmarinov
ASKER
Thanks for your fast answer Martin,
The reason is, because i would like to use the "OnMouseOver" and "OnMouseOut" events. The example is below:
<a id="AddToCart" href="#" runat="server" CommandName="AddToCart" onMouseOver="MM_swapImage( 'add1','', 'images/ad d_h.gif',1 )" onMouseOut="MM_swapImgRest ore()"><im g src="images/add.gif" name="add1" width="43" height="19" border="0" id="add"></a>
The OnMouse events doing the buttons lively. The JavaScript functions (MM_swapImgRestore() and MM_swapImage()) doing the changes.
So, I use here the CommandName property, but it doesn't working. Do you know why?
Thanks a lot Martin.
The reason is, because i would like to use the "OnMouseOver" and "OnMouseOut" events. The example is below:
<a id="AddToCart" href="#" runat="server" CommandName="AddToCart" onMouseOver="MM_swapImage(
The OnMouse events doing the buttons lively. The JavaScript functions (MM_swapImgRestore() and MM_swapImage()) doing the changes.
So, I use here the CommandName property, but it doesn't working. Do you know why?
Thanks a lot Martin.
ASKER
The Final solution is as follows:
<asp:linkbutton id="AddToCart" runat="server" onMouseOver="MM_swapImage( 'Add','',' images/ren tal_add_h. gif',1)" onMouseOut="MM_swapImgRest ore()"><im g src="images/rental_add.gif " name="add1" width="43" height="19" border="0" id="add"></asp:linkbutton>
And the VB code:
Sub Items_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
Dim ItProductID As New TextBox, ItQuantity As New TextBox
ItProductID = CType(e.Item.FindControl(" ItemProduc tID"), TextBox)
ItQuantity = CType(e.Item.FindControl(" ItemQuanti ty"), TextBox)
If Not (ItQuantity.Text Is DBNull.Value) Then
'Here call your AddToCart method
End If
End Sub
Thanks.
<asp:linkbutton id="AddToCart" runat="server" onMouseOver="MM_swapImage(
And the VB code:
Sub Items_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
Dim ItProductID As New TextBox, ItQuantity As New TextBox
ItProductID = CType(e.Item.FindControl("
ItQuantity = CType(e.Item.FindControl("
If Not (ItQuantity.Text Is DBNull.Value) Then
'Here call your AddToCart method
End If
End Sub
Thanks.
<asp:textbox ID="Quantity" size="3" Runat="server"><%# GetQuantity(value) </asp:textbox>
this calls the function "GetQuantity" which you can define in your code behind. just pass in whatever value you need to put in the quantity.