日期:2014-05-18  浏览次数:20702 次

C#菜鳥請問RadioButtonList
我想要實現讓RadioButtonList有3個選項
RadioButtonList讀取資料庫內容顯示資料
A選項
B選項
C選項

點選A選項會判斷,連接到A的專屬頁面
點選B選項會判斷,連接到B的專屬頁面

請教各位大俠該怎麼寫,謝謝

------解决方案--------------------
C# code

<asp:RadioButtonList ID="rbl" runat="server" AutoPostBack="false" RepeatLayout="Table" OnSelectedIndexChanged="rbl_SelectedIndexChanged">
    <asp:ListItem Value="1">A選項</asp:ListItem>
    <asp:ListItem Value="2">B選項</asp:ListItem>
    <asp:ListItem Value="3">C選項</asp:ListItem>
</asp:RadioButtonList>

public int sel;
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
        sel = Convert.ToInt32(rbl.SelectedItem.Value);
        swith(sel)
        {
              case 1:
                      Response.Redirect("A.aspx");
                      break;
              case 2:
                      Response.Redirect("B.aspx");
                      break;
              case 3:
                      Response.Redirect("C.aspx");
                      break;
              default:
                      break;
        }
}