Javascript hide multiple gridview rows

DropDownList Elements

a
b
c

Gridview

X | B | C | D | E
a | 1 | 2 | 3 | 4
b | 2 | 2 | 2 | 2
c | 3 | 3 | 3 | 3

When DropDownList.SelectedItem=a

Hide GridView.Rows= bandc


When DropDownList.SelectedItem=b

Hide GridView.Rows= aandc


etc.


Does anyone know javascript for this client side?

0
source share
2 answers

Assuming the id of the dropdown alphaand gridview tbl, you can do it like this:

$(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();
    }
  });   
});

Here is an example in JS BIN

+2
source

Sharing under the pseudo-code below:

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

All Articles