Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Search option using textbox key press for gridview with paging in c# asp.net using jquery?

My search code is running fine without paging but when i set allow paging true so,
It was searching only 5 rows.

My search code not running with paging.
i have use input type text:

HTML
<input name="search" type="text" id="search" value="" autocomplete="off" onkeyup="Search_Gridview(this,'gvEmpSkillDetails')" class="form-control" placeholder="Search">


for searching.

Please help me.

Thanks in Advance.

Ankit Agarwal

What I have tried:

<script type="text/javascript">
function Search_Gridview(strKey, strGV) {
var strData = strKey.value.toLowerCase().split(" ");
var tblData = document.getElementById(strGV);
var rowData;
for (var i = 1; i < tblData.rows.length; i++) {
rowData = tblData.rows[i].innerHTML;
var styleDisplay = 'none';
for (var j = 0; j < strData.length; j++) {
if (rowData.toLowerCase().indexOf(strData[j]) >= 0)
styleDisplay = '';
else {
styleDisplay = 'none';
break;
}
}
tblData.rows[i].style.display = styleDisplay;
}
}
</script>
Posted
Updated 27-Jul-16 8:06am
v3

Since you are using javascript to query/filter the data which is displaying on the screen(gridview) , Obviously it will filter only the data available on the screen(gridivew) based on your if conditions.
This is how javascript works

When you are using pagination (eg 10 records per page), The Server will transfer only 10 records to the web browser in an HTML Table[^] format and you code will query that 10 records only, not the entire dataset.
if you want to filter the entire data, you should remove the pagination, so that the whole dataset will be transferred to the browser in an HTML Table format.

Your Javascript code has the Control over DOM [^]only, not to the server data, if you want to do the filtering over server data by using Javascript then you will have to use JQuery AJAX[^] to get the data asynchronously and based on the JSON [^] result data, build the HTML table dynamically[^].

This is how you can resolve your issue.
 
Share this answer
 
 
Share this answer
 
Comments
Agarwal1984 27-Jul-16 7:20am    
I saw both link but one image column also in my gridview.
SO, how to add or bind image column using c# or jquery?
Agarwal1984 27-Jul-16 7:21am    
<asp:ImageField DataImageUrlField="EMPIMG" HeaderText="Person" ControlStyle-Width = "100" ControlStyle-Height = "100">
<controlstyle width="100px" height="100px">

<HeaderStyle Font-Bold="True" />

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