Hi,
You need to store total line count in hidden fields and then loop through count and all controls have a patern with increasing number. Identify ur controls to implement ur business logic using java script on focus lost of ur control.
I have emplemented same. I think It will help you.
function CalculateRes() {
var totalColReserve = 0;
var totalColPaid = 0;
var totalColrec = 0;
var totalColTotal = 0;
var Count = document.getElementById("hidCount").value;
for (var i = 2; i <= Count; i++) {
var inc = i;
if (i < 10) {
inc = "0" + i;
}
if (i != Count) {
var ReserveVal = document.getElementById("GridReserveDetail_ctl" + inc + "_txtReserveAmt");
var paidVal = document.getElementById("GridReserveDetail_ctl" + inc + "_txtPaidAmt");
var RecVal = document.getElementById("GridReserveDetail_ctl" + inc + "_txtRecoveryAmt");
var RtotalVal = document.getElementById("GridReserveDetail_ctl" + inc + "_txtTotalAmt");
ReserveVal.value = addCommas(parseFloat(unComma(ReserveVal.value)).toFixed(2));
paidVal.value = addCommas(parseFloat(unComma(paidVal.value)).toFixed(2));
RecVal.value = addCommas(parseFloat(unComma(RecVal.value)).toFixed(2));
RtotalVal.value = addCommas(parseFloat(unComma(RtotalVal.value)).toFixed(2));
if (ReserveVal.value == "0") {
ReserveVal.value = "0.00";
}
if (paidVal.value == "0") {
paidVal.value = "0.00";
}
if (RecVal.value == "0") {
RecVal.value = "0.00";
}
}
if (i == Count) {
inc = i + 1;
if (inc < 10) {
inc = "0" + inc;
}
}
RtotalVal.value = parseFloat(unComma(ReserveVal.value)) + parseFloat(unComma(paidVal.value)) - parseFloat(unComma(RecVal.value));
RtotalVal.value = addCommas(parseFloat(unComma(RtotalVal.value)).toFixed(2));
if (RtotalVal.value == "0") {
RtotalVal.value = "0.00";
}
totalColReserve = parseFloat(unComma(totalColReserve)) + parseFloat(unComma(ReserveVal.value));
totalColPaid = parseFloat(unComma(totalColPaid)) + parseFloat(unComma(paidVal.value));
totalColrec = parseFloat(unComma(totalColrec)) + parseFloat(unComma(RecVal.value));
totalColTotal = parseFloat(unComma(totalColTotal)) + parseFloat(unComma(RtotalVal.value));
}
document.getElementById("hidRecoverySum").value = parseFloat(document.getElementById("hidRecoverySum").value) + parseFloat(totalColrec);
return totalColPaid;
}