Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, 30 January 2020

Add checkbox in asp gridview with select all functionality

Introduction
This code will show you how to add checkbox in asp gridview with select all functionality and also how to get selected checkbox gridview rows values. I have added only two columns in gridview but you can use as per your requirement.
Code
.aspx page code
add javascript reference to your page.
  1. <script type="text/javascript" src="jquery.js"></script>  
  2. <script type="text/javascript">  
  3.    $(document).ready(function () {  
  4.       var headerChk = $(".chkHeader input");  
  5.       var itemChk = $(".chkItem input");  
  6.          headerChk.click(function () {  
  7.             itemChk.each(function () {  
  8.                this.checked = headerChk[0].checked;  
  9.          })  
  10.    });  
  11.    itemChk.each(function () {  
  12.          $(this).click(function () {  
  13.             if (this.checked == false)  
  14.             {  
  15.                headerChk[0].checked = false;  
  16.              }  
  17.             })  
  18.          });  
  19.    });  
  20. </script>  
  21.    
  22. <asp:GridView ID="gvdashboard" ClientIDMode="Static" runat="server" class="table table-striped"  
  23. AutoGenerateColumns="False" GridLines="None" CellPadding="4" ForeColor="#333333">  
  24. <AlternatingRowStyle BackColor="White" />  
  25.    <Columns>  
  26.       <asp:TemplateField ItemStyle-Width="10px" HeaderStyle-Width="10px">  
  27.          <HeaderTemplate>  
  28.             <asp:CheckBox ID="chkSelectAll" CssClass="chkHeader" runat="server" />  
  29.          </HeaderTemplate>  
  30.       <ItemTemplate>  
  31.       <asp:CheckBox ID="chkRow" CssClass="chkItem" runat="server" />  
  32.       </ItemTemplate>  
  33.       <HeaderStyle Width="10px"></HeaderStyle>  
  34.          <ItemStyle Width="10px"></ItemStyle>  
  35.      </asp:TemplateField>  
  36.      <asp:BoundField DataField="ID" HeaderText="ID" ></asp:BoundField>  
  37.      <asp:BoundField DataField="Name" HeaderText="Name"></asp:BoundField>  
  38. </Columns>  
  39.    <EditRowStyle BackColor="#2461BF" />  
  40.    <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />  
  41.    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />  
  42.    <PagerStyle CssClass="pagination" BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />  
  43.    <RowStyle BackColor="#EFF3FB" />  
  44.    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />  
  45.    <SortedAscendingCellStyle BackColor="#F5F7FB" />  
  46.    <SortedAscendingHeaderStyle BackColor="#6D95E1" />  
  47.    <SortedDescendingCellStyle BackColor="#E9EBEF" />  
  48.    <SortedDescendingHeaderStyle BackColor="#4870BE" />  
  49. </asp:GridView>     

.aspx.cs page code 
  1. foreach (GridViewRow row in gvdashboard.Rows)  
  2. {  
  3.    if (row.RowType == DataControlRowType.DataRow)  
  4.       {  
  5.          CheckBox chkRow = (row.Cells[0].FindControl("chkRow"as CheckBox);  
  6.       if (chkRow.Checked)  
  7.       {  
  8.          // do whatever your logic  
  9.       }  
  10.    }  
  11. }

Tuesday, 7 January 2020

Bank IFSC code validation using Javascript or jquery

Introduction 

Here is a validation code for bank IFSC code.

IFSC code format : 
- Starting 4 should be only alphabets[A-Z]
Remaining 7 should be accepting only alphanumeric

Code



  1. <script type="text/javascript">  
  2. $(document).ready(function(){   
  3.       
  4. $(".ifsc").change(function () {    
  5. var inputvalues = $(this).val();    
  6.   var reg = /[A-Z|a-z]{4}[0][a-zA-Z0-9]{6}$/;  
  7.                 if (inputvalues.match(reg)) {  
  8.                     return true;  
  9.                 }  
  10.                 else {  
  11.                      $(".ifsc").val("");  
  12.                     alert("You entered invalid IFSC code");  
  13.                     //document.getElementById("txtifsc").focus();  
  14.                     return false;  
  15.                 }  
  16. });    
  17.   
  18. });  
  19. </script>  
  20.   
  21. IFSC : <input type="text" class="ifsc">  

PAN no validation using javascript or jquery

Introduction  

Here is a javascript code to validate PAN no.

PAN no sample : ABCDE1234F

Code


  1. <script type="text/javascript">  
  2. $(document).ready(function(){   
  3.       
  4. $(".pan").change(function () {    
  5. var inputvalues = $(this).val();    
  6.   var regex = /[A-Z]{5}[0-9]{4}[A-Z]{1}$/;  
  7.   if(!regex.test(inputvalues)){    
  8.   $(".pan").val("");  
  9.   alert("invalid PAN no");  
  10.   return regex.test(inputvalues);  
  11.   }  
  12. });    
  13.   
  14. });  
  15. </script>  
  16.   
  17. PAN : <input type="text" class="pan">  


Email id validation using jquery or javascript

Introduction

Here is a javascript function to validate email id.
you need to add class "email" in text control.

Code 


  1. <script type="text/javascript">      
  2. $(document).ready(function () {      
  3.   
  4. $(".email").change(function () {  
  5. var inputvalues = $(this).val();  
  6. var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;  
  7. if(!regex.test(inputvalues)){  
  8. alert("invalid email id");  
  9. return regex.test(inputvalues);  
  10. }  
  11. });  
  12.   
  13.  });          
  14. </script>          
  15.         
  16. Html input type text        
  17. Email : <input type="text" class="email" >  

GST number validation using javascript or jquery

Introduction 
GST number validation using Javascript or jquery on text change event.
you need to apply "gst" class to control and add below javascript function.

GST no sample : 05ABDCE1234F1Z2

Code 

  1. <script type="text/javascript">    
  2. $(document).ready(function () {    
  3. $(".gst").change(function () {  
  4.                 var inputvalues = $(this).val();  
  5.                 var gstinformat = new RegExp('^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]1}[1-9A-Z]{1}Z[0-9A-Z]{1}$');  
  6.                 if (gstinformat.test(inputvalues)) {  
  7.                     return true;  
  8.                 } else {  
  9.                     alert('Please Enter Valid GSTIN Number');  
  10.                     $(".gst").val('');  
  11.                     $(".gst").focus();  
  12.                 }  
  13.             });        
  14.  });        
  15.   </script>    
  16.     
  17. ASP Textbox      
  18. <asp:TextBox ID="txtGST" MaxLength="15" runat="server" class="gst form-control mandatory" ClientIDMode="Static" placeholder="GST Reg No."></asp:TextBox>        
  19.       
  20. Html input type text      
  21. <input type="text" class="gst" >      
  22.