How do I multiply 2 columns in a Repeater?

I have a shopping script using a repeater to display items and prices.

On a row by row basis, I need to multiply the price by the quantity to get a sub total

The repeater is called "rpBasket". I figured I'd use a method "rowTotal()" and grab (and convert) the qty textbox and label price multiply them and return it. Here's the item template for the repeater:

            <td><asp:Label id="lbl_ProdCode" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "prod_code") %>'></asp:Label> </td>
            <td><asp:TextBox id="txtQty" runat="server" size="1" Text='<%#DataBinder.Eval(Container.DataItem, "prod_qty") %>'></asp:TextBox></td>
            <td><asp:Label id="lbl_ProdName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "prod_name") %>'></asp:Label> </td>
            <td><asp:Label id="lbl_Price" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "prod_price") %>'></asp:Label></td>

This worked on a simple test (where I created 2 literals and added them) so I guess I'm just dumb when it comes to getting the values out of the repeater. Here's the method which is naff and doesn't work but you can see what I am trying to do...

            public string rowTotal(object source, RepeaterItemEventArgs e)
                  decimal prod_price;
                  decimal prod_qty;
                  string prod_total;
                  prod_price = Convert.ToDecimal(((Label) e.Item.FindControl("lbl_Price")).Text);
                  prod_qty = Convert.ToDecimal(((TextBox) e.Item.FindControl("txtQty")).Text);
                  prod_total = Convert.ToString(prod_price * prod_qty);
                  return prod_total;

Thanks in advance...
Who is Participating?
gregoryyoungConnect With a Mentor Commented:
hmm ...

why not just do this ...

<%# (Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "Price")) *Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "Quantity"))).ToString()%>
w3digitalAuthor Commented:
Thanks. Now why didn't I think of that... Ah yes, I'm a newbie. That'll be it!

Nice one and thanks very much!
providing there are no nulls :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.