2011-05-20 55 views
0

DropDownList的项JavaScript的隐藏多个gridview的行

a 
b 
c 

的GridView

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?

回答

2

假设DropDownList的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

+0

@jsang你如何让它再次显示所有行?如果有dropdownlist.item =“ALL”,则重置为显示所有行。 – 2011-05-20 07:56:51

+0

@jsang由于某种原因,它不适用于我的项目。 2011-05-20 08:12:21

+1

@Pod我按照您的要求编辑了我的答案。 – 2011-05-20 08:19:38

0

共享一个子伪代码如下:

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 :-)