我在JavaScript中创建了一个遍历网格视图中所有文本框的函数,并在数量和价格的基础上进行计算。
网格视图代码:
<asp:GridView ID="grdAddToList" runat="server" AutoGenerateColumns="False" CellSpacing="0"
CellPadding="0" PageSize="100" PagerStyle-HorizontalAlign="Right" DataKeyNames="UniqueId"
EmptyDataText="No Record found..">
<Columns>
<asp:BoundField HeaderText="Product Name" DataField="ProductName" />
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" onChange="return CalculateTotalAmount();" runat="server" Text='<%# Eval("Quantity") %>'></asp:TextBox>
<asp:Label ID="lblOfferPriceCalc" runat="server" Text='<%# Eval("ProductOfferPriceCalc") %>' style="display:none" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Offer Price" DataField="ProductOfferPrice" />
<asp:BoundField HeaderText="Product Details" DataField="ProductDetails" />
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="btnRemove" runat="server" Text="Remove" CommandName="Remove" OnClick="btnRemove_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Java-Script Code:
function CalculateTotalAmount() {
var gv = document.getElementById("<%=grdAddToList.ClientID %>");
var lblOfferPrice = document.getElementById("<%=lblTotal.ClientID %>");
var gvRowCount = gv.rows.length;
var TotalValue = 0;
var rwIndex = 1;
for (rwIndex; rwIndex <= gvRowCount - 1; rwIndex++) {
var offerprice = gv.rows[rwIndex].cells[1].childNodes[0].value;
var InsertedQuantity = gv.rows[rwIndex].cells[1].childNodes[2].innerHTML;
TotalValue = parseInt(TotalValue) + (parseInt(offerprice) * parseInt(InsertedQuantity));
}
lblOfferPrice.innerHTML = TotalValue;
return false;
}
它在我的系统上工作正常但是当它部署在我朋友的系统上时它无法正常工作。