Showing posts with label Search. Show all posts
Showing posts with label Search. Show all posts

Wednesday, 30 November 2016

How to seach in gridview using key up method like table in html


// Add a gridview to the aspx page and a textbox for search. bind the gridview for populating the data

Put this java script in head of the aspx page

  <script type="text/javascript">
        function filter2(phrase) {
            var words = phrase.value.toLowerCase().split(" ");
            var table = document.getElementById("<%=GridView1.ClientID %>");
            var ele;
            for (var r = 1; r < table.rows.length; r ) {
                ele = table.rows[r].innerHTML.replace(/<[^>] >/g, "");
                var displayStyle = 'none';
                for (var i = 0; i < words.length; i ) {
                    if (ele.toLowerCase().indexOf(words[i]) >= 0)
                        displayStyle = '';
                    else {
                        displayStyle = 'none';
                        break;
                    }
                }
                table.rows[r].style.display = displayStyle;
            }
        }
    </script>

Now add this function "keyup" in the texbox which will be used to enter the keyword like this

 <asp:TextBox ID="TextBox2" runat="server" class="form-control" onkeyup="filter2(this)"></asp:TextBox>