Wednesday, 21 January 2015

how to check status of checkboxes in gridview columns on click of button by using the javascript

 I have used checkbox column in gridview.when  clicking on the linkbutton, it should be checked that checkboxes in gridview are checked or not. If none checkbox is checked then it should display alert("Check the unverified Checkboxes"). 


  <script type="text/javascript">
     function Chkverified()
      {
          var grid = document.getElementById("<%=gvwLeaseReviewSummary.ClientID %>");
          var icount=0;
            
       for( var i=0; i<grid.all.length;i++)
       
      {
      var chkverified =grid.all[i];
      
      if(chkverified != null && chkverified.type == "checkbox"
                   && chkverified.checked == false )
         {
                icount =icount + 1;
       
         }
      }
      
      if(icount > 0)
      {
     alert("Please Check the unverified Checkboxes");
     return false;
     }
      else
      {
      return true;
      }
       }




 </script>


OnClientClick="Chkverified()"


                          Or 




server side code :
            Dim icount As Integer = 0


            For Each gvwRow As GridViewRow In Gridview1.Rows.Rows
                Dim chkverified As CheckBox = DirectCast(Gridview1.Rows(gvwRow.RowIndex).FindControl("chkVerified"), CheckBox)


                If chkverified.Checked = False Then
                    icount = icount + 1
                End If


            Next


            If icount > 0 Then
                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "confirm", "confirm('Please check the Unverified Records')", True)
                   Exit Sub
            Else
                ' If there is no unverified records then submit the report.
                SubmitFunction() // This method should executed without any unverified checkboxes in gridview.
            End If

No comments:

Post a Comment