如何自动计算合计,谢谢各位朋友?
在Datagrid中
pro_id pro_price(文本框) pro_amount(文本框) 小计
1 50.50 5
3 10.60 6
.. ... ....
Lebel totalmomey.text=得到总金额.
当在文本框输入值时,自动计算小计和总金额.
不通过数据库.
[解决办法]
在DataGrid_ItemDataBing里面
TextBox price=(TextBox)e.Item.FindControl( "pro_price ");
TextBox amount=(TextBox)e.Item.FindControl( "pro_amount ");
Label total=(Label)e.Item.FindControl( "totalmomey ");
price.Attributes.add( "onchange ", "Sum(this,document.getElementById( ' "+amount.ID+ " '),document.getElementById( ' "+total.ID+ " ')) ");
amount.Attributes.add( "onchange ", "Sum(document.getElementById( ' "+amount.ID+ " ',this,,document.getElementById( ' "+total.ID+ " ')) ");
HTML
function Sum(obj1,obj2,obj3)
{
var price=obj1.value;
var amount=obj2.value;
if(price== " ")
price=0;
if(amount== " ")
amount=0;
var total=parseInt(price)+parseInt(amount);
obj3.innerText=total;
}
=============================================
大概的是这样了..有点小问题勿怪..
[解决办法]
price.Attributes.add( "onchange ", "Sum(this,document.getElementById( ' "+amount.ID+ " '),document.getElementById( ' "+total.ID+ " ')) ");
amount.Attributes.add( "onchange ", "Sum(document.getElementById( ' "+amount.ID+ " ',this,,document.getElementById( ' "+total.ID+ " ')) ");
应该是clientid而不是id!!!