如何在GridView中进行计算 [英] how to do calculations in gridview

查看:86
本文介绍了如何在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.

推荐答案

检查这些博客
GridView中数据库驱动的客户端计算 [ http://geekswithblogs. net/dotNETvinz/archive/2010/12/09/faq-gridview-calculation-with-javascript --- editable-price-field.aspx [
check these blogs
Database driven client side calculations in GridView[^]
http://geekswithblogs.net/dotNETvinz/archive/2010/12/09/faq-gridview-calculation-with-javascript---editable-price-field.aspx[^]
--NDK


查看此处:



您需要将总行数存储在隐藏字段中,然后循环计数,并且所有控件的样式都随着数字的增加而增加.确定您的控件以使用Java脚本来实现您的业务逻辑,以专注于失去您的控件.


我做了同样的事情.我想这会帮到你.
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;

// 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中进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆