Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
<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
ASP.NET
<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 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..
Posted
Updated 10-Jul-16 19:46pm

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

failed.

Learn to use the debugger to see what append in code.
 
Share this answer
 
Comments
KyLim0211 10-Jul-16 23:50pm    
onkeyup="Search_Gridview(this, 'gvTest')"

anything wrong with this? my gridview id is gvTest
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)"
 
Share this answer
 
v3
Comments
KyLim0211 11-Jul-16 0:00am    
uncaught SyntaxError: Unexpected token <
getting this error
try using Client ID
JavaScript
function Search_Gridview(strKey) {
          var strGV = '<%= gvTest.ClientID %>';
 
Share this answer
 
Comments
huicho 6-Aug-19 12:32pm    
Escellent!!!
Karthik_Mahalingam 30-Dec-22 1:26am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900