javascript隐藏多个gridview行
DropDownList项目
a b c
网格视图
X | B | C | D | E a | 1 | 2 | 3 | 4 b | 2 | 2 | 2 | 2 c | 3 | 3 | 3 | 3
当DropDownList.SelectedItem
= a
隐藏GridView.Rows
= b
& c
当DropDownList.SelectedItem
= b
隐藏GridView.Rows
= a
& c
等等
有人知道这个客户端的javascript吗?
假设下拉列表的id是alpha
和gridview的tbl
,你可以这样做:
$(document).ready(function(){ $("#alpha").change(function(){ var selVal = $(this).find(":selected").text(); var rows = $("#tbl tr:gt(0)"); if (selVal == "ALL") { $("#tbl tr").show(); } else { var rowToShow = rows.find("td:eq(0)").filter(":contains(" + selVal + ")").closest("tr"); rows.show().not( rowToShow ).hide(); } }); });
这是JS BIN中的一个例子
共享下面的子伪代码:
Array listFromGridView = [a,b,c]; // get parent dropdownbox and save for future reference var drop=$("#dropdownBoxID); drop.bind('click',function(e){ // get all element in an array Array tempList= listFromGridView; // remove the element which was clicked // $(this) = the dropdownbox, $(this).val() = selected value tempList.remove( $(this).val() ); // iterate and hide rows foreach( element el in tempListView) // code for hide goes here }); // Done :-)