Search This Blog

Sunday, March 25, 2012

Loop through gridview rows and access each row's element by jquery


Example for checkbox:

    var gridView1Control = document.getElementById('<%= GridView1.ClientID %>');
   $.each($('input:checkbox', gridView1Control),function(index, item){
   //item represent individual checkbox 
  });

Other Way:
$('#<%=grid.ClientID%>')
     .find('tr')
     .each(function(row) {
          $(this).find('input,select,textarea')
                .each(function(col) {
                      $ctl = $(this);
                      if ($ctl.is('select')) {
                          //dropdown code
                      } else if  (ctl.is('input:checkbox') {
                          //checkbox code
                      }  else {
                          // textbox/textarea code
                      }
                 });
      });
}); 

No comments:

Post a Comment