Mega Code Archive

 
Categories / ASP.Net / Asp Control
 

Use Switch to read Radio Button Choice (C#)

<script language="C#" runat="server"> void Page_Load() {   if (Page.IsPostBack) {     switch(Destination.SelectedItem.Value)      {       case "B":         Message.Text = "You selected B";         break;        case "C":         Message.Text = "You selected C";         break;        case "D":          Message.Text = "Your selected D";         break;        default:         Message.Text = "you did not select a destination";         break;      }   } } </script> <html> <head></head> <body>   <form runat="server">   Select your choice of destination:   <br><br>   <asp:radiobuttonlist id="Destination" runat="server">     <asp:listitem>B</asp:listitem>     <asp:listitem>C</asp:listitem>     <asp:listitem>D</asp:listitem>   </asp:radiobuttonlist>   <br><br>   <input type="submit" value="Submit Choice">   <br><br>   <asp:label id="Message" runat="server"/> </form> </body> </html>