将javascript值分配给Gridview中的标签. [英] Assign a Javascript Value to a label in Gridview....

查看:60
本文介绍了将javascript值分配给Gridview中的标签.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将javascript变量分配给gridview中的标签.
目前,我收到错误消息

I would like to be able to assign a javascript variable to a label in a gridview.
At the moment I get the error message

Microsoft JScript runtime error: Unable to set value of the property 'innerHTML': object is null or undefined



我的代码在下面...



My code is below...

<script language="Javascript" type="text/javascript">
    var grandTotal = 0;
    var percentTotal = 0;
    function multiply2(Rate, number, total) {

            var grid = document.getElementById('GridView5');
            var num = parseFloat(document.getElementById(number).value);
            
            
            var tot = document.getElementById(total);
            var totValue = parseFloat(((Rate * num)));
            var totValueRound = Math.round(totValue);
            var totValueRound = totValue;
            tot.innerHTML = "$" + totValueRound.toFixed(2);
            grandTotal += totValue;
            percentTotal = grandTotal * 10 / 100;
            for (j = 0; j < grid.rows.length - 1; j++) {
            grid.rows[grid.rows.length - 1].cells[2].children[0].innerHTML = "$" + grandTotal.toFixed(2);
        }
        document.getElementById('lblTotal').innerHTML = percentTotal.toFixed(2);
       
    } 
</script>

推荐答案

" + totValueRound.toFixed( 10 / 100 ; for (j = 0 ; j< grid.rows.length- 1 ].cells [ 2 ].children [ 0 ].innerHTML = "
" + totValueRound.toFixed(2); grandTotal += totValue; percentTotal = grandTotal * 10 / 100; for (j = 0; j < grid.rows.length - 1; j++) { grid.rows[grid.rows.length - 1].cells[2].children[0].innerHTML = "


" + grandTotal.toFixed(文档 .getElementById(' lblTotal') .innerHTML = percentTotal.toFixed( 2 ); } < / 脚本 >
" + grandTotal.toFixed(2); } document.getElementById('lblTotal').innerHTML = percentTotal.toFixed(2); } </script>


在ASP.NET中,控件没有在代码中赋予它们的值.在网格中尤其如此.如果标签位于一列中,则该列中的每个值都不能具有相同的名称,对吗?最简单的方法是查看源代码并找到客户端名称.正确的方法是使用有问题的对象的ClientId属性(在行数据绑定事件中,如果它在网格内),以便无论您如何使用,都可以发出知道要查找正确ID的javascript代码更改.
In ASP.NET, your controls do not have the value you gave them in your code. This is especially true in a grid. If the label is in a column, then there''s no way that each value in that column has the same name, right ? The easy way is to view source and find the client side name. The correct way is to use the ClientId property of the object in question ( in the row data bound event, if it''s inside a grid ), so that you emit javascript which knows the correct id to look for, no matter how your code changes.


这篇关于将javascript值分配给Gridview中的标签.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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