javascript隐藏多个gridview行

时间:2011-05-20 06:41:20

标签: c# javascript jquery asp.net gridview

DropDownList项目

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 个答案:

答案 0 :(得分:2)

假设下拉列表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

中的示例

答案 1 :(得分: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 :-)