aspx页面代码片断:性别
<asp:RadioButton ID="r1_1" runat="server" GroupName="g1" Text="男" />
<asp:RadioButton ID="r1_2" runat="server" GroupName="g1" Text="女" />
<br />
选择
<asp:CheckBox ID="c1_1" runat="server" Text="选择1" />
<br />
<asp:CheckBox ID="c1_2" runat="server" Text="选择2"/>
<br />后台代码片断:foreach (Control cl in this.form1.Controls)
{
if (cl is RadioButton)
{
RadioButton tempR = ((RadioButton)cl);
if (tempR.Checked)
{
//此处省略
}
}
if (cl is CheckBox)
{
CheckBox tempC = ((CheckBox)cl);
if (tempC.Checked)
{
//此处省略
}
}
}
现在的问题是运行后,当遍历到是RadioButton的时候, if (cl is CheckBox)这句竟然为true,为什么呢?如何修改?谢谢!
<asp:RadioButton ID="r1_1" runat="server" GroupName="g1" Text="男" />
<asp:RadioButton ID="r1_2" runat="server" GroupName="g1" Text="女" />
<br />
选择
<asp:CheckBox ID="c1_1" runat="server" Text="选择1" />
<br />
<asp:CheckBox ID="c1_2" runat="server" Text="选择2"/>
<br />后台代码片断:foreach (Control cl in this.form1.Controls)
{
if (cl is RadioButton)
{
RadioButton tempR = ((RadioButton)cl);
if (tempR.Checked)
{
//此处省略
}
}
if (cl is CheckBox)
{
CheckBox tempC = ((CheckBox)cl);
if (tempC.Checked)
{
//此处省略
}
}
}
现在的问题是运行后,当遍历到是RadioButton的时候, if (cl is CheckBox)这句竟然为true,为什么呢?如何修改?谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货