0

I have a gridview with rows and with pagination. I have the below jquery that searches for text in a text box and on clicking on a button it searches and displays all rows containing that text, but currently it only checks the first page. My question is how it can search through all the pages of the gridview control

$(document).ready(function() {
    $('#<%=lblNoRecords.ClientID%>').css('display','none');

    $('#<%=btnSubmit.ClientID%>').click(function(e)
    {
        // Hide No records to display label.
        $('#<%=lblNoRecords.ClientID%>').css('display','none');
        //Hide all the rows.
        $("#<%=gdRows.ClientID%> tr:has(td)").hide();

        var iCounter = 0;
        //Get the search box value
        var sSearchTerm = $('#<%=txtSearch.ClientID%>').val();

        //if nothing is entered then show all the rows.
        if(sSearchTerm.length == 0)
        {
          $("#<%=gdRows.ClientID%> tr:has(td)").show();
          return false;
        }
        //Iterate through all the td.
        $("#<%=gdRows.ClientID%> tr:has(td)").children().each(function()
        {
            var cellText = $(this).text().toLowerCase();
            //Check if data matches
            if(cellText.indexOf(sSearchTerm.toLowerCase()) >= 0)
            {   
                $(this).parent().show();
                iCounter++;
                return true;
            }
        });
        if(iCounter == 0)
        {
            $('#<%=lblNoRecords.ClientID%>').css('display','');
        }
        e.preventDefault();
    })
})
michael marmah
  • 157
  • 1
  • 2
  • 13
  • Is your GridView and/or `btnSubmit` inside an UpdatePanel? If so check my answer here https://stackoverflow.com/questions/46003867/class-attribute-on-gridview-doesnt-work-after-button-click – VDWWD Sep 01 '17 at 21:21
  • Yes my Gridview is inside an updatePanel.I have seen your anwere but I didnt quite get it, how it relates to mine.Please if you can explain it further to me I would appreciate it very much. – michael marmah Sep 01 '17 at 22:14
  • The binding to the button is lost when updating the DOM. You need to execute `$('#<%=btnSubmit.ClientID%>').click` again after UpdatePanel refresh. – VDWWD Sep 01 '17 at 22:40

0 Answers0