Note that the following code requires jquery to be loaded, so please go to the official website to download the latest version. Copy code The code is as follows: .org/1999/xhtml" > js operates GridView to realize automatic calculation <!-- <BR>table,tr,td{text-align:center;} <BR>input{width:50px;text-align:center;} <BR><br>--></ style><style type="text/css" bogus="1"> table,tr,td{text-align:center;} <br>input{width:50px;text-align:center;} <br> < /script> <br><script type="text/javascript"><!-- <BR>//Global<BR>var tbl; <BR>//Change the total amount and total quantity<BR>function setTotal(){ <BR>var totalAmount=0;//Total amount<BR>var totalCount=0;//Total quantity<BR>if(tbl!=null&&tbl.rows.length>2)//The header occupies one row <br>{ <br>for(var n=1;n<tbl.rows.length-1;n)//The rows array starts from 0, and the table occupies one row<BR>{ <BR>//Total quantity <BR>if(!isNaN(tbl.rows[n].cells[2].childNodes[0].value)) <BR>{ <BR>totalCount =Number(tbl.rows[n].cells[2] .childNodes[0].value); <BR>} <BR>//Total amount<BR>if(!isNaN(tbl.rows[n].cells[3].innerText))//Determine whether it is a number<BR>{ <BR>totalAmount =Number(tbl.rows[n].cells[3].innerText); <BR>} <BR>} <BR>} <BR>tbl.rows[tbl.rows.length- 1].cells[2].innerText=totalCount; <BR>tbl.rows[tbl.rows.length-1].cells[3].innerText=totalAmount; <BR>} <BR>//The unit price changes according to Use the row number to find the quantity and amount of the same row, <BR>//These values can be bound with index='<%#Container.DataItemIndex %>'<br>function fPrice(rowId,val){ <br>tbl .rows[Number(rowId)].cells[3].innerText= <br>Number(val)* Number(tbl.rows[Number(rowId)].cells[2].childNodes[0].value); <br>} <br>//Number changes<br>function fCount(rowId,val){ <br>tbl.rows[Number(rowId)].cells[3].innerText= <br>Number(val)* Number (tbl.rows[Number(rowId)].cells[1].childNodes[0].value); <br>} <br>//Limit only numbers can be entered <br>function checknum() <br>{ <br>if((event.keyCode>=48&&event.keyCode<=57)||event.keyCode==8||(event.keyCode>=96&&event.keyCode<=105) <BR>||event.keyCode== 46||event.keyCode==37||event.keyCode==39||event.keyCode==190||event.keyCode==110) <BR>{ <BR>event.returnValue=true; <BR> } <BR>else <BR>{ <BR>event.returnValue=false; <BR>} <BR><br>} <br>jQuery(function(){ <BR>//Initialize table <BR>// tbl=document.getElementById("GridView1"); <BR>tbl=$("#GridView1").get(0);//Return DOM object<BR>//Restrictions on input keyboard<BR>jQuery("input ").keydown(function(){ <BR>checknum(); <BR>}).keyup(function(){ <BR>setTotal(); <BR>}); <BR>}); <BR> <br>// --> No. Unit price Quantity Amount 1 2 ; Total