- <ddHEAD runat="server">
-
- <ddSCRIPT language=javascript>
- function SelAllBox(obj)
- {
- var ctls=document.getElementsByTagName("INPUT");
- document.getElementById("<%=HiddenchkIDBox.ClientID%>").value="";
- for(i=0;i<ctls.length;i++)
- {
- if(ctls[i].type=="checkbox")
- {
- ctls[i].checked=obj.checked;
- if (ctls[i]!=obj && obj.checked==true)
- document.getElementById("<%=HiddenchkIDBox.ClientID%>").value+=","+ctls[i].value;
- }
- }
- }
-
- function AddRemoveValues(oChk)
- {
- if(oChk.checked)
- document.getElementById("<%=HiddenchkIDBox.ClientID%>").value += "," + oChk.value;
- else
- document.getElementById("<%=HiddenchkIDBox.ClientID%>").value = document.getElementById("<%=HiddenchkIDBox.ClientID%>").value.replace("," + oChk.value,"");
- }
-
- </SCRIPT>
-
-
-
- <FORM id=form1 runat="server">
- <DIV style="TEXT-ALIGN: center">
- <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>
- </DIV>
- <INPUT id=HiddenchkIDBox style="WIDTH: 120px" type=hidden runat="server">
- </FORM>
-
-
-
-
- 还有另外一种:
- public void SelectedAll(bool checkstate)
- {
- HdnSelectedValues.Value = "";
- for (int i = 0; i < this.GridView1.Rows.Count; i++)
- {
- HtmlInputCheckBox ckb = (HtmlInputCheckBox)this.GridView1.Rows[i].Cells[0].FindControl("ChkSelect");
- ckb.Checked = checkstate;
- HdnSelectedValues.Value += "," + ckb.Value;
- }
- }
还有另外一种:
public void SelectedAll(bool checkstate)
{
HdnSelectedValues.Value = "";
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
HtmlInputCheckBox ckb = (HtmlInputCheckBox)this.GridView1.Rows[i].Cells[0].FindControl("ChkSelect");
ckb.Checked = checkstate;
HdnSelectedValues.Value += "," + ckb.Value;
}
}