1

I have a gridview populating from a dataset. Gridview contains thousands of records so I have implemented paging using a dataview. After populating gridview I am searching the text in the columns of the gridview using java script and the highlighting the text. It works to the end of the rows of gridview.

I want to implement like search should continue to the next page of the gridview using javascript.

The gridivew pager controls are added to the panel to make separate from gridview.

the search functionality is happening from a pop up window. I am accessing the controls in the panel from the javascript in the pop up window like this. But it returns zero as length.

var controls = window.opener.document.getElementById('ctl00_ContentPlaceHolder1_pnlpager1').getElementsByTagName("input");  
             alert(controls.length);   
       for (var i = 0; i < controls.length; i++)  

       alert(controls[i]);

can we search the gridview columns in all pages of a gridview using a javascript

Please check the code in the javascript.

function searchback()
{//alert(window.opener)
    var rowid = -1 
    if (typeof(window.opener) != "undefined" && window.opener != null)
    {

         i = 1;
        if ((document.getElementById('<%= hdn_value.ClientId %>').value!="")&&(document.getElementById('<%= hdn_value.ClientId %>').value!="undefined"))
        {
            if ((document.getElementById('<%= hdn_ddVal.ClientId %>').value!="")&&(document.getElementById('<%= hdn_ddVal.ClientId %>').value!="undefined"))
            {
            //alert(document.getElementById('<%= hdn_ddVal.ClientId %>').value)
                if (document.getElementById('<%= hdn_ddVal.ClientId %>').value==document.getElementById('colNos').value)
                {
                    i=document.getElementById('<%= hdn_value.ClientId %>').value;
                    i--;
                }
            }
        }
      //alert(i);
        var rows = window.opener.document.getElementById(opener.gvwListViewId).getElementsByTagName('tr');             
        var searchData = document.getElementById('<%= hdn_SearchText.ClientId %>').value.toLowerCase();   
        //alert(searchData)
        var searchExp = new RegExp(searchData);
        //alert(searchExp)
        var colNo = document.getElementById('colNos').value;
        document.getElementById('<%= hdn_ddVal.ClientId %>').value=document.getElementById('colNos').value;
      //  alert(colNo)
       // alert(rows.length)
        while(i < rows.length)
        {               
            if(searchExp.test(rows[i].getElementsByTagName('td')[colNo].innerText.toLowerCase()))
            {             

            if (document.getElementById('rbtn_MatchFullWord').checked)
            {
                if (rows[i].getElementsByTagName('td')[colNo].innerText.toLowerCase().replace(/^\s+|\s+$/g,"")!=searchData.replace(/^\s+|\s+$/g,""))
                {                     
                    i--;
                    continue;
                }
            }
                //alert(i)
                // rows[i].click();
               // alert('done boss')   
               // rows[i].cells[colNo].blur()
                if ((document.getElementById('<%= hdn_value.ClientId %>').value!="")&&(document.getElementById('<%= hdn_value.ClientId %>').value!="undefined"))
                {
                    rows[document.getElementById('<%= hdn_value.ClientId %>').value].cells[colNo].style.backgroundColor=document.getElementById('<%= hdn_backColor.ClientId %>').value;
                }
                document.getElementById('<%= hdn_backColor.ClientId %>').value=rows[i].cells[colNo].style.backgroundColor;
                rows[i].cells[colNo].style.backgroundColor ='yellow';
                rows[i].scrollIntoView(false);
                document.getElementById('<%= hdn_value.ClientId %>').value = i; 
                break;
            }
            i--;   

        }
       // alert("hdn2:"+ document.getElementById('<%= hdn_value.ClientId %>').value);


        if (i == 0)
        {



            if (window.opener.document.getElementById('ctl00_toolbar1_ibtn_Next') != null)
            {
                if(yesno("Finished searching the current page. Do you want to search in the next page?", "Search") == 6)
                {
                    window.opener.document.getElementById('ctl00_toolbar1_ibtn_Next').click();
                }
            }
            else if (document.getElementById('<%= hdn_value.ClientId %>').value == "")
            {
            alert("Search Completed No Records Found");
            }

            else
            {
                alert('Search Completed');
            }
        }
    }
  //  alert('outside if');
    if (rowid != -1)
    {
   // alert('rowid'+rowid)
        window.returnValue = rowid;
        window.close;
    }
}
3
  • could you please post the code you have written...that would be helpful... Jul 24, 2012 at 9:06
  • i have added code. please check the code Jul 24, 2012 at 9:11
  • are you making use of client side paging techniques?
    – deostroll
    Sep 10, 2012 at 18:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.