[英]aspx GridView filter with javascript
我正在使用帶有c#代碼VS 2010的Asp.net。我有一個帶有gridview的頁面,其中顯示了一個成員列表。 我想使用不帶任何ajax的javascript作為用戶類型來過濾網格中的行。 例如,如果用戶鍵入“ Jo”,則帶有“ John”和“ Jonny”的行將保留,而其他行將被過濾掉。
謝謝。
這是您需要的工作示例
function SetupFilter(textboxID, gridID, columnName) {
$('#' + textboxID).keyup(function () {
var index;
var text = $("#" + textboxID).val();
$('#' + gridID + ' tbody tr').each(function () {
$(this).children('th').each(function () {
if ($(this).html() == columnName)
index = $(this).index();
});
$(this).children('td').each(function () {
if ($(this).index() == index) {
var tdText = $(this).children(0).html() == null ? $(this).html() : $(this).children(0).html();
if (tdText.indexOf(text, 0) > -1) {
$(this).closest('tr').show();
} else {
$(this).closest('tr').hide();
}
};
});
});
});
};
在頁面頭或啟動.js文件中包含上述代碼段之后,接下來要做的就是為每個要主動過濾網格的文本框調用以下代碼:
$(function () { SetupFilter("myTextBox", "myGridView", "My Column Name"); });
當然,在這種情況下,JQuery將成為您的朋友。 www.jquery.com試用一些通用用法教程。 然后在初始化腳本引用對象中,直接搜索所有帶有這些字母的TD並添加“ .each()。remove(this);”
應該可以,否則請再粘貼一些代碼。
LG喬納斯·普利特
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.