B
bob garbados
I need to create a page that displays all of the products from a table and
allows for add to cart functionality.
My thoughts were to display all of the products in table rows using a
repeater. Each row has a text box for quantity to order and a button to add
the product and quantity to the shopping cart. I can dynamically assign the
CommandArgument to my button and figure out which one was clicked, but I
can't figure out how to get the value from the textbox. I am getting errors
when I try to dynamically name the textbox. Any input is appreciated.
Here's the html...
<asp:repeater id="rptProducts" runat="server">
<ItemTemplate>
<tr>
<td class="ListContentRow" valign="top">
<img src="images\<%# DataBinder.Eval(Container.DataItem,
"ProductThumbnail") %>"/>
</td>
<td class="ListContentRow" valign="top">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<a href="">
<font class="BoldLabel">
<%# DataBinder.Eval(Container.DataItem, "ProductName") %>
</font>
</a>
</td>
</tr>
<tr>
<td valign="top">
<font class="ListText">
<%# DataBinder.Eval(Container.DataItem, "ProductBriefDesc")
%><br/>
</font>
</td>
</tr>
</table>
</td>
<td class="ListContentRow" valign="top">
<font class="BoldLabel">
<%# DataBinder.Eval(Container.DataItem, "ProductPrice",
"{0:C}") %>
</font>
</td>
<td class="ListContentRow">
<table cellpadding="4" cellspacing="0">
<tr>
<td valign="top">
<font class="BoldLabel">Qty: </font>
<asp:textbox Columns="3" runat="server"/>
</td>
</tr>
<tr>
<td valign="top">
<asp:button
Text="add to cart"
CssClass="AddToCartButton"
OnCommand="btnAddToCart_Command"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,
"ProductId") %>'
runat="server" />
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
allows for add to cart functionality.
My thoughts were to display all of the products in table rows using a
repeater. Each row has a text box for quantity to order and a button to add
the product and quantity to the shopping cart. I can dynamically assign the
CommandArgument to my button and figure out which one was clicked, but I
can't figure out how to get the value from the textbox. I am getting errors
when I try to dynamically name the textbox. Any input is appreciated.
Here's the html...
<asp:repeater id="rptProducts" runat="server">
<ItemTemplate>
<tr>
<td class="ListContentRow" valign="top">
<img src="images\<%# DataBinder.Eval(Container.DataItem,
"ProductThumbnail") %>"/>
</td>
<td class="ListContentRow" valign="top">
<table cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<a href="">
<font class="BoldLabel">
<%# DataBinder.Eval(Container.DataItem, "ProductName") %>
</font>
</a>
</td>
</tr>
<tr>
<td valign="top">
<font class="ListText">
<%# DataBinder.Eval(Container.DataItem, "ProductBriefDesc")
%><br/>
</font>
</td>
</tr>
</table>
</td>
<td class="ListContentRow" valign="top">
<font class="BoldLabel">
<%# DataBinder.Eval(Container.DataItem, "ProductPrice",
"{0:C}") %>
</font>
</td>
<td class="ListContentRow">
<table cellpadding="4" cellspacing="0">
<tr>
<td valign="top">
<font class="BoldLabel">Qty: </font>
<asp:textbox Columns="3" runat="server"/>
</td>
</tr>
<tr>
<td valign="top">
<asp:button
Text="add to cart"
CssClass="AddToCartButton"
OnCommand="btnAddToCart_Command"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,
"ProductId") %>'
runat="server" />
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:repeater>