本文介绍了如何在GridView中进行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在c#.net的Datagrid中进行计算(例如在MS Excel中).

表示当我们进入Gridcell时自动更新,然后结果将自动更新.

How do we do the calculations (like in MS Excel)in Datagrid in c#.net.

Means automatic updates when we enter the Gridcell then the result will be updated automatically.

推荐答案



function CalculateRes() {
            var totalColReserve = 0;
            var totalColPaid = 0;
            var totalColrec = 0;
            var totalColTotal = 0;

// Hidden field to get count
            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;
        }


这篇关于如何在GridView中进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 08:08