更新转发器中项目的小计

时间:2013-05-02 09:00:27

标签: c# asp.net repeater

我有用于显示项目名称,价格,用于输入金额的输入文本框和用于显示每个项目的价格*金额的标签的转发器。 我可以用JavaScript计算价格*金额。 这是代码(如果你需要的话)我用来找到结果

function setAmountOther(row) {

    var firstUnderscore = row.indexOf("_");
    var lastUnderscore = row.lastIndexOf("_");

    var totalOther = 0;

    var rowID = row.substring(firstUnderscore, lastUnderscore + 1); // get the control id _ctlXX_ (where XX is row number)

    var rowAmont = Number($('#rptOtherProducts' + rowID + 'txtProductQuantityOther').val()); // get the amount of the product

    var rowPrice = Number($('#rptOtherProducts' + rowID + 'lblProductsPriceOther').text()); // get the price of the product

    totalForRow = rowAmont * rowPrice; // get total for row

    totalOther += totalForRow; // get total for order

    $('#rptOtherProducts' + rowID + 'lblProductTotalOther').html(totalForRow);  // set the total price of the item


} 

问题是如何将每个项目的所有结果添加到显示项目小计的标签中,以及如果有人更改项目数量,我如何更新它? 例如:如果我输入2并且项目的价格是20,结果是40,小计是40,但是我输入1结果是20,但小计仍然是40。

JavaScript中的任何解决方案,带有C#的asp.net或任何其他想法都将非常有用。 (我搜索但没有找到任何有用的东西,也许我搜索错误的关键字)

如果您还有其他需要,请告诉我。

谢谢

编辑: 转发器中的源代码:

<ItemTemplate>
                            <div class="divProductsMain" style="margin: 0 -116px 0 0">
                                <div class="divProdcutTotal">
                                    <label id="lblProductTotalOther" runat="server">
                                        0</label>&nbsp;&#8362;
                                </div>
                                <div class="divProductsQuantity">
                                    <input type="text" id="txtProductQuantityOther" runat="server" class="txtProductQuantity"
                                        maxlength="3" onkeyup="setAmountOther(this.id)" />
                                </div>
                                <div class="divProductsPrice">
                                    <asp:Label ID="lblProductsPriceOther" runat="server"><%#Eval("Price", "{0:0.00}")%></asp:Label>&nbsp;&#8362;
                                </div>
                                <div class="divProductDescription">
                                    <asp:Label ID="lblProductDescriptionOther" runat="server"><%#Eval("Name")%></asp:Label>
                                </div>
                                <div class="divComputerCode">
                                    <asp:Label ID="lblComputerCodeOther" runat="server"><%#Eval("ComputerCode")%></asp:Label>
                                </div>
                            </div>
                        </ItemTemplate>

如果您还有其他需要请告诉我。

1 个答案:

答案 0 :(得分:0)

调用计算功能 您接受金额和价格的文本框的OnKeyUp(事件)

相关问题