Thursday, March 29, 2012

Select All Check Box In Asp .Net With Java Script

Add This Code In Header Section Of your Aspx Page
1.


   1:  <script type="text/javascript">   
   2:     function SelectAllAndDeSelectAllCheckBox(Chk)
   3:  { 
 
   5:        var oItem = Chk.children; 
   6:      var theBox= (spanChk.type=="checkbox") ? Chk: Chk.children.item[0]; 
   7:       xState=theBox.checked;  
   8:       elm=theBox.form.elements; 
    9:       for(i=0;i 
  10:    
  11:           if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)  
  13:           {   
  16:             if(elm[i].checked!=xState)    
  19:           }
  20:  script>



After The Add this code in Header Section You Need take A Grid View and Write This Code ..


   1:   
   2:  <asp:templatefield headertext="Select">
   3:    <headertemplate>  
   4:    <input blogger_onclick="javascript:SelectAllAndDeSelectAllCheckBox(this);"  
         id="chkAll" runat="server" type="checkbox">  
   5:   headertemplate> 
   6:    <itemtemplate>
   7:   <asp:checkbox blogger_oncheckedchanged="CheckBox1_CheckedChanged"  
         id="CheckBox1" runat="server" autopostback="true">
   8:    asp:checkbox>itemtemplate>
   9:   asp:templatefield>




Hope This Help You

No comments:

Post a Comment