开发者

How to assign +ve value instead of -ve value to the GridView Cell using JavaScript?

I want to assign value to the GridView Column Name TaxAmount. To get the TaxAmount I am doing some calculation, Even if the Calculation retruns -ve value, I want to assign +ve value to the Column.

For ex, if the Calculation returns 5.003 then it should be 5.003 even if returns -5.003 then it should be 5.003.

How to assign, I have given my JavaScript below.

var taxgrid = document.getElementById('<%=gvAttribute.ClientID %>');
var rwIndex = 1; 
var taxamount = 0*1;
for (rwIndex; rwIndex <= gvRowCount - 1; rwIndex++) 
{
    for(i = 0; i < taxip.length; i+= 4)
    { 
         var sign = taxip[i+2].value;
         var tax = taxip[i+3].value;
         taxamount = parseFloat(taxamount) + (sign == '+' ? 1 : -1) * parseFloat(tax);
         taxgrid.rows[rwIndex].开发者_运维问答cells[5].getElementsByTagName('input')[0].value = taxamount;
    }
}

I used TemplateFields in the GridView.


Have you tried Math.abs()

To know more about Math.abs() check w3schools

Try like followng

taxgrid.rows[rwIndex].cells[5].getElementsByTagName('input')[0].value =Math.abs(taxamount);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜