无法读取null java脚本错误的属性'rows' [英] Cannot read property 'rows' of null java script error

查看:59
本文介绍了无法读取null java脚本错误的属性'rows'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript">
        function Search_Gridview(strKey, strGV) {
            var strData = strKey.value.toLowerCase().split(" ");
            var tblData = document.getElementById(strGV);
            var rowData;
            for (var i = 1; i < tblData.rows.length; i++) {
                rowData = tblData.rows[i].innerHTML;
                var styleDisplay = 'none';
                for (var j = 0; j < strData.length; j++) {
                    if (rowData.toLowerCase().indexOf(strData[j]) >= 0)
                        styleDisplay = '';
                    else {
                        styleDisplay = 'none';
                        break;
                    }
                }
                tblData.rows[i].style.display = styleDisplay;
            }
        }    
    </script>





html



html

<div style="border: 1px solid Black; width: 800px; padding: 20px; height: 350px;
            font-size: 20px;">
            Search :
            <asp:TextBox ID="txtSearch" runat="server" Font-Size="20px" onkeyup="Search_Gridview(this, 'gvTest')"></asp:TextBox><br />
            <br />
            <asp:GridView ID="gvTest" runat="server" OnPageIndexChanging="GrdRole_PageIndexChanging" PageSize="10000">
                <columns>
               <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox ID="chkSelect" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            </columns>
            </asp:GridView>
        </div>





i获取错误 - > for(var i = 1; i< tblData.rows.length; i ++)Gridview_Search.aspx:171 Uncaught TypeError:无法读取属性'rows'的null



我尝试了什么:



请指导我,不知道我哪里做错了,谢谢..



i getting error in --> for (var i = 1; i < tblData.rows.length; i++) "Gridview_Search.aspx:171 Uncaught TypeError: Cannot read property 'rows' of null"

What I have tried:

please guide me ,no idea where i did wrong,thank you..

推荐答案

简单,该消息告诉您

a类型的变量 null 没有属性 rows

这意味着 tblData null 和那个

Simple, the message tells you that
a variable of type null have no property rows
this imply that tblData is null and that
var tblData = document.getElementById(strGV);



失败。



学习使用调试器查看附加内容代码。


failed.

Learn to use the debugger to see what append in code.


使用clientId属性而不是硬编码文本,因为asp.net将生成不同的id。



<脚本类型=text / javascript>

var gvTestClientId ='<%= gvTest.Clien tID%>';

< / script>



onkeyup =Search_Gridview(this,gvTestClientId)
Use clientId property instead of hard coded text as asp.net will generate different id.

<script type="text/javascript">
var gvTestClientId = '<% =gvTest.ClientID %>';
</script>

onkeyup="Search_Gridview(this, gvTestClientId)"


尝试使用客户ID

try using Client ID
function Search_Gridview(strKey) {
          var strGV = '<%= gvTest.ClientID %>';


这篇关于无法读取null java脚本错误的属性'rows'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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