当前位置: 代码迷 >> ASP.NET >> :CheckBox控件的全选或取消
  详细解决方案

:CheckBox控件的全选或取消

热度:9608   发布时间:2013-02-25 00:00:00.0
求助: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;
}
}
  相关解决方案