checkbox全选

  1. <ddHEAD runat="server">   
  2.        
  3.     <ddSCRIPT language=javascript>   
  4.         function SelAllBox(obj)   
  5.         {   
  6.             var ctls=document.getElementsByTagName("INPUT");   
  7.             document.getElementById("<%=HiddenchkIDBox.ClientID%>").value="";   
  8.             for(i=0;i<ctls.length;i++)    
  9.             {    
  10.                 if(ctls[i].type=="checkbox")    
  11.                 {   
  12.                     ctls[i].checked=obj.checked;   
  13.                     if (ctls[i]!=obj && obj.checked==true)   
  14.                         document.getElementById("<%=HiddenchkIDBox.ClientID%>").value+=","+ctls[i].value;   
  15.                 }   
  16.             }   
  17.         }   
  18.            
  19.         function AddRemoveValues(oChk)    
  20.         {    
  21.             if(oChk.checked)   
  22.                 document.getElementById("<%=HiddenchkIDBox.ClientID%>").value += "," + oChk.value;    
  23.             else  
  24.                 document.getElementById("<%=HiddenchkIDBox.ClientID%>").value = document.getElementById("<%=HiddenchkIDBox.ClientID%>").value.replace("," + oChk.value,"");    
  25.         }   
  26.   
  27.     </SCRIPT>   
  28.   
  29.   
  30.   
  31.     <FORM id=form1 runat="server">   
  32.          <DIV style="TEXT-ALIGN: center">   
  33.             <TABLE style="WIDTH: 437px" cellSpacing=0 cellPadding=0 border=0><TBODY><TR><TD><ASP:GRIDVIEW id=GridView1 runat="server" Font-Size="12px" Width="422px" AutoGenerateColumns="False" BackColor="White" BorderColor="#6895B4" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" HorizontalAlign="Center" Height="1px" PageSize="5" OnRowCommand="GridView1_RowCommand"><FOOTERSTYLE BackColor="White" BorderColor="#6895B4" BorderStyle="Solid" BorderWidth="1px" ForeColor="#000066" /><COLUMNS><ASP:TEMPLATEFIELD><ITEMTEMPLATE><INPUT id=ChkBox onclick=AddRemoveValues(this) type=checkbox value='<%#Eval("UserName") %>'><%#Eval("NUMID") %> </ITEMTEMPLATE><HEADERTEMPLATE><INPUT id=SelAllChkBox onclick=SelAllBox(this) type=checkbox>全选 </HEADERTEMPLATE><ITEMSTYLE Width="140px" HorizontalAlign="Center" /><HEADERSTYLE BorderColor="#6895B4" BorderStyle="Solid" BorderWidth="1px" /></ASP:TEMPLATEFIELD></COLUMNS><ROWSTYLE BorderColor="#6895B4" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" ForeColor="#000066" /><SELECTEDROWSTYLE BackColor="#669999" ForeColor="White" Font-Bold="True" /><PAGERSTYLE BackColor="White" BorderColor="White" BorderStyle="None" BorderWidth="0px" HorizontalAlign="Right" ForeColor="#000066" /><HEADERSTYLE BackColor="#CCD7DD" BorderColor="#6895B4" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" ForeColor="Black" Font-Bold="True" /><EMPTYDATAROWSTYLE BorderColor="#6895B4" BorderStyle="Solid" BorderWidth="1px" /><ALTERNATINGROWSTYLE BorderColor="#6895B4" BorderStyle="Solid" BorderWidth="1px" /></ASP:GRIDVIEW></TD></TR></TBODY></TABLE>   
  34.         </DIV>   
  35.                         <INPUT id=HiddenchkIDBox style="WIDTH: 120px" type=hidden runat="server">   
  36.     </FORM>   
  37.   
  38.   
  39.   
  40.   
  41. 还有另外一种:   
  42. public void SelectedAll(bool checkstate)   
  43.         {   
  44.             HdnSelectedValues.Value = "";   
  45.             for (int i = 0; i < this.GridView1.Rows.Count; i++)   
  46.             {   
  47.                 HtmlInputCheckBox ckb = (HtmlInputCheckBox)this.GridView1.Rows[i].Cells[0].FindControl("ChkSelect");   
  48.                 ckb.Checked = checkstate;   
  49.                 HdnSelectedValues.Value += "," + ckb.Value;   
  50.             }   
  51.         }  

posted on 2007-06-25 13:42  周伟  阅读(298)  评论(0编辑  收藏  举报

导航