C# 在JavaScript的Asp.net标签中显示Gridview列总数

C# 在JavaScript的Asp.net标签中显示Gridview列总数,c#,javascript,asp.net,C#,Javascript,Asp.net,我想在标签中显示Gridview列总计,它位于Gridview之外。我编写了bellow函数,并在blur上调用它,但for循环未执行,它不会进入for循环。非常感谢您的帮助 function footertotal() { var col1; var grid = 0; var totalcol1=0; grid = document.getElementById('<%=Grid1.ClientID %>'); for (var i = 1; i < grid.

我想在
标签
中显示
Gridview
列总计,它位于
Gridview
之外。我编写了bellow函数,并在blur上调用它,但for循环未执行,它不会进入for循环。非常感谢您的帮助

function footertotal() {
 var col1;
 var grid = 0;
 var totalcol1=0;
 grid = document.getElementById('<%=Grid1.ClientID %>');
  for (var i = 1; i < grid.rows.length; i++) {
   totalcol1 += parseFloat(Grid1.Rows[i].Cells['Tprice'].Value);
  }
 document.getElementById('<%=LblSubTotal.ClientID %>').innerHTML = totalcol1.toFixed(2).toString();
}
函数footertotal(){
col1变种;
var网格=0;
var totalcol1=0;
grid=document.getElementById(“”);
对于(var i=1;i
我认为您没有很好地使用方法
getElementById
。 你必须这样做:

function footertotal() {
     var col1;
     var totalcol1=0;
     var grid = document.getElementById('Grid1.ClientID');
     for (var i = 1; i < grid.rows.length; i++) {
      totalcol1 += parseFloat(Grid1.Rows[i].Cells['Tprice'].Value);
     }
document.getElementById('LblSubTotal.ClientID').innerHTML = totalcol1.toFixed(2).toString();

  }
函数footertotal(){
col1变种;
var totalcol1=0;
var grid=document.getElementById('Grid1.ClientID');
对于(var i=1;i

有关更多帮助,请查看此处:

能否显示您的aspx页面以确保
ID
,请让我们查看HTML输出:-)