1

I used the search function and I've seen a lot of topics about "how to highlight a text " but I couldn't find a way to implement it in my asp.net website project.

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

How can I do it ? I would like someone to explain step by step , I need to do this for tomorrow and I'm not very advanced. ty

Inzi Irina
  • 267
  • 2
  • 5
  • 14

1 Answers1

0

I think it could help you try it and add

$(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(); 
                    }
                });
            }
        });
Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95