How can I highlight a word within gridview

2020-02-07 01:16发布

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

3条回答
我想做一个坏孩纸
2楼-- · 2020-02-07 02:02
var gv = document.getElementById("#GridView1");

    for (var i = 0; i < gv.all.length; i++) {
var cellValue = grid.rows[i].cells[0].elements[0];
cellValuestyle.background = '#DD00DD';
}
查看更多
\"骚年 ilove
3楼-- · 2020-02-07 02:05

search the text, dress them with a tag like <label>, and don't forget to add highlight style for the labels.

查看更多
疯言疯语
4楼-- · 2020-02-07 02:08

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();
                    }
                });
            }
        });
查看更多
登录 后发表回答