关于c#中RadioButtonList控件的取值问题
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Font-Bold="True"
Font-Names="FangSong_GB2312" Font-Size="Medium"
RepeatDirection="Horizontal" Height="23px"
style="margin-left: 16px" Width="291px" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="1" Selected="True" Text="学生">学生</asp:ListItem>
<asp:ListItem Value="2" Text="教师">教师</asp:ListItem>
<asp:ListItem Value="3" Text="管理员">管理员/asp:ListItem>
</asp:RadioButtonList>
后台想通过选择的用户,验证用户名和密码,点击登录,跳转到相应的页面:
protected void LoginButton_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
Response.Redirect("Student.aspx");
}
else if (RadioButtonList1.SelectedIndex == 1)
{
Response.Redirect("Teacher.aspx");
}
else if (RadioButtonList1.SelectedIndex == 2)
{
Response.Redirect("Admin.aspx");
}
}
省略了判断的语句,直接跳转,结果根本没有判断取值,不反应,请高手指点!万分感谢! 展开
我试过,没有问题的
我没有用RadioButtonList1_SelectedIndexChanged这个,不知道这个事件你写的是什么代码
前台代码:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" >
<asp:ListItem Value="1" Selected="True" Text="学生">学生</asp:ListItem>
<asp:ListItem Value="2" Text="教师">教师</asp:ListItem>
<asp:ListItem Value="3" Text="管理员">管理员</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="LoginButton" runat="server" Text="LoginButton" OnClick="LoginButton_Click" />
登录:
protected void LoginButton_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
Response.Redirect("Student.aspx");
}
else if (RadioButtonList1.SelectedIndex == 1)
{
Response.Redirect("Teacher.aspx");
}
else if (RadioButtonList1.SelectedIndex == 2)
{
Response.Redirect("Admin.aspx");
}
}
protected void LoginButton_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "1")
{
Response.Redirect("Student.aspx");
}
else if (RadioButtonList1.SelectedValue == "2")
{
Response.Redirect("Teacher.aspx");
}
else if (RadioButtonList1.SelectedValue== "3")
{
Response.Redirect("Admin.aspx");
}
}