任何实现高亮文本的简单方法都会产生gridview?

时间:2012-03-04 17:16:02

标签: c# asp.net sql

我使用了搜索功能,我看过很多关于“如何突出显示文本”的主题,但我找不到在asp.net网站项目中实现它的方法。

I'm using a gridview and for search function I'm using this :

 SqlDataSource1.SelectCommand = "select * from TableName where Name like '%" + TextBox1.Text + "%' or SecName like '%" + TextBox1.Text + "%'";
         SqlDataSource1.DataBind();

我该怎么办?我希望有人一步一步解释,明天我需要这样做,而且我不是很先进。 TY

1 个答案:

答案 0 :(得分:0)

我认为它可以帮助您尝试并添加

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