遍历页面上所有的RadioButton与CheckBox出现一个奇怪的问题.请大家帮忙看一下!
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) { //此处省略 } } }