Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,
I have textbox and gridview in asp.net page
<asp:textbox id="textSearch" runat="server">
<asp:gridview id="grd" runat="server">
also
I use this Code Jquery to search in grd by txtSearch



$('input[id$=txtSearch]').keyup(function () {
_this = this;

$.each($("[id*=grd] tbody").find("tr"), function () {
if ($(this).text().toLowerCase().indexOf($(_this).val().toLowerCase()) == -1)
$(this).hide();
else
$(this).show();
});

})



I'm already connect grd by datatable and every thing work
BUT !!!
after search very well
the header of grd is hide
AND
The question :
How can search by write in txtSearch text and keep the header row show ?
thanks for All.

What I have tried:

I tried to make search by loop in grd
and start loop from the row index =0
but I can't get the solve
because I'm not know the right way
thanks
Posted
Updated 1-Sep-19 9:14am

1 solution

I forgot how autogenerated gridview HTML markup is rendered in the browser, but you can try escaping the first <tr> of the table. Your code would now look something like this:

JavaScript
$('input[id$=txtSearch]').keyup(function () {
	_this = this;

	$.each($("[id*=grd]").find("tr:not(:first)"), function () {
		if ($(this).text().toLowerCase().indexOf($(_this).val().toLowerCase()) == -1)
			$(this).hide();
		else
			$(this).show();
	});

});


The key there is to use the jQuery selector tr:not(:first) to prevent the first row to be hidden.

You can also try looking at QuickSearch plugin as demontrated in this article here: https://www.aspsnippets.com/Articles/Implement-Client-Side-search-in-GridView-using-jQuery-in-ASPNet.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900