日期:2014-05-18  浏览次数:20485 次

求助:CheckBox控件的全选或取消
例如有十个CheckBox控件,我要全部选定,可以用循环句全选吗?

------解决方案--------------------
<form id= "form1 " runat= "server ">
<asp:CheckBox ID= "CheckBox1 " runat= "server " />
<asp:CheckBox ID= "CheckBox2 " runat= "server " />
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "Button " />
</form>

protected void Button1_Click(object sender, EventArgs e)
{
CheckBox chkTemp;
foreach (Control c in this.form1.Controls)
{
chkTemp = c as CheckBox;
if (chkTemp != null)
chkTemp.Checked = true;
}
}