且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 gridview 中突出显示单词

更新时间:2022-04-22 07:59:00

如果你想做这个客户端,请按照以下步骤操作:

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

向您的页面添加 jQuery 引用.添加一个文本输入调用 txt_Search.

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

然后使用这个脚本:

 $(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();
                    }
                });
            }
        });