有10个radiobutton,后台 控制哪个被选中,有个奇怪的现象.不知何解. 请大牛赐教!
vv587 2019-03-08 09:57:11 1.页面中放置10个 服务器控件 radiobutton,ID从 rb0 到 rb10, GroupName 均为 "k"
2.页面中有一List控件, 项 从 0 到 10
3.List控件的 SelectedIndexChanged()事件中, 根据 选中项 设置对应的 radiobutton 选中.
问题:
页面首次加载时, 点击List中的项, 从小到大点击, 代码起作用, 但是只要点完了 大数, 再点小数就不起作用了.
备注:
将List换成10个按钮, 现象一致.
换成radiobuttonlist控件,就没有问题了.
请大牛解答,产生这个问题的原是什么?
前台代码:
<asp:ListBox ID="List1" runat="server" class="ddlyxg"
AutoPostBack="True" OnSelectedIndexChanged="List1_SelectedIndexChanged"
Height="228px">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
</asp:ListBox>
<asp:RadioButton ID="rb0" runat="server" Text="0分" GroupName="k" />
<asp:RadioButton ID="rb1" runat="server" Text="1分" GroupName="k" />
<asp:RadioButton ID="rb2" runat="server" Text="2分" GroupName="k" />
<asp:RadioButton ID="rb3" runat="server" Text="3分" GroupName="k" />
<asp:RadioButton ID="rb4" runat="server" Text="4分" GroupName="k" />
<asp:RadioButton ID="rb5" runat="server" Text="5分" GroupName="k" />
<asp:RadioButton ID="rb6" runat="server" Text="6分" GroupName="k" />
<asp:RadioButton ID="rb7" runat="server" Text="7分" GroupName="k" />
<asp:RadioButton ID="rb8" runat="server" Text="8分" GroupName="k" />
<asp:RadioButton ID="rb9" runat="server" Text="9分" GroupName="k" />
<asp:RadioButton ID="rb10" runat="server" Text="10分" GroupName="k" />
后台代码:
protected void List1_SelectedIndexChanged(object sender, EventArgs e)
{
int score = Convert.ToInt32(List1.SelectedValue);
switch (score)
{
case 0: rb0.Checked = true; break;
case 1: rb1.Checked = true; break;
case 2: rb2.Checked = true; break;
case 3: rb3.Checked = true; break;
case 4: rb4.Checked = true; break;
case 5: rb5.Checked = true; break;
case 6: rb6.Checked = true; break;
case 7: rb7.Checked = true; break;
case 8: rb8.Checked = true; break;
case 9: rb9.Checked = true; break;
case 10: rb10.Checked = true; break;
default:
break;
}
}