Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to search the all records in gridview when gridview allow paging is true
I tried the below code it will work on only on that page

What I have tried:

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;
}
}
Posted
Updated 18-Mar-18 21:24pm

1 solution

If you are binding your GridView at the server (code behind) then there's no way for you to search the records when paging is enabled. A paged grid will only render the data one page at a time so your JavaScript doesn't have access to it. You may want to use a client-side Grid that allows you to do what you want. The idea is to grab all the records from a service call (assuming you are using AJAX to populate your grid) and then search the records from it and then rebuild your client-side GridView.

One example is using bootstrap datatables: Bootstrap Table With Sorting, Searching and Paging using dataTable.js (Responsive)[^]

You can see the live demo here: A demo of table with pagination and search options[^]
 
Share this answer
 
Comments
Member 13723018 19-Mar-18 5:19am    
i want search in gridview not in html table
F-ES Sitecore 19-Mar-18 7:08am    
View the source of your page, a GridView is shown as a table on the client-side, javascript runs on the client-side so your js needs to work with tables, the concept of a "GridView" only exists in your server-code.

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