Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I highlight a word within gridview

How can I highlight the text of a query in the gridview control?

like image 213
John Mokien Avatar asked Mar 03 '12 14:03

John Mokien


Video Answer


1 Answers

if you want do this client side please follow this steps:

add jQuery reference to your page.add a text input calles txt_Search.

and then use this script:

 $(document).ready(function () {
            $('#txt_Search').keyup(function () {
                searchTable($(this).val());
            });

            function searchTable(inputVal) {
                var table = $('#GridView1');
                table.find('tr').each(function (index, row) {
                    var allCells = $(row).find('td');
                    if (allCells.length > 0) {
                        var found = false;
                        allCells.each(
            function (index, td) {
                var regExp = new RegExp(inputVal, 'i');
                if (regExp.test($(td).text())) {
                    found = true;
                    return false;
                }});
                        if (found == true) $(row).show(); else $(row).hide();
                    }
                });
            }
        });
like image 154
Arian Avatar answered Sep 23 '22 16:09

Arian