2011-07-07 19 views

回答

1

如果您正在使用jQuery再考虑优秀的jQuery数据表插件,它的成效斐然,一个简单的表元素:http://www.datatables.net/

3

我写了下面的功能我自己,你只是把它要过滤的列索引,以及您要过滤的文本框的ID。

不要忘记到GridView /表名称更改为您的

function filter(columnIndex, id) { 
     var filterText = $("#" + id).val().toLowerCase(); 

     var cellText = ""; 
     var cellTextSampleToCompare = ""; 

     $("#<%=YOUR_GRIDVIEW_NAME.ClientID%> tr:has(td)").each(function() { 
      cellText = $(this).find("td:eq(" + columnIndex + ")").text().toLowerCase(); 
      cellText = $.trim(cellText); //removes the spaces in the starting of the string value if exist 
      cellTextSampleToCompare = cellText.substring(0, filterText.length); 

      if (filterText != cellTextSampleToCompare) { 
       $(this).css('display', 'none'); 
      } 
      else { 
       $(this).css('display', ''); 
      } 
     }); 
    } 
+0

作品非常感谢! – Eliseo

0

这可能不是回答你的问题,但它可能会帮助人们谁到这里来。

$(document).ready(function() { 
      $("#txtID").keyup(function() { 
       _this = this; 
       $.each($("#grdEmployee tbody").find("tr:has(td)"), function() { 
        if ($(this).text().toLowerCase().indexOf($(_this).val().toLowerCase()) != -1) 
         $(this).show(); 
        else 
        $(this).hide(); 

       }); 
      }); 
     });