这是我在asp.net中的以下内容
<asp:RadioButtonList ID="RbList" runat="server"
onselectedindexchanged="RbList_SelectedIndexChanged">
<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="2"></asp:ListItem>
</asp:RadioButtonList>
<asp:Label ID="lbltest" runat="server"></asp:Label>
这是我的RBList_SelectedIndexChanged
事件。
int i = RbList.SelectedIndex;
if (i == 1)
{
lbltest.Text = "You have click on male";
}
if (i == 2)
{lbltest.Text = "You have click on female";}
现在,我希望在选择项目1时,文本标签必须符合所选项目的radiobutton列表。
怎么可能这样呢?
问候。
答案 0 :(得分:3)
将您的代码更改为以下内容:
int i = RbList.SelectedIndex; if (i == 0) { lbltest.Text = "You have click on male"; } else if (i == 1) { lbltest.Text = "You have click on female"; }