Slide 12.5: Text boxes (cont.)
Slide 12.7: Radio button lists
Home

Radio Buttons


The RadioButton control permits you to intersperse the radio buttons in a group with other content in the page. The buttons in the sample are grouped logically because they all share the same GroupName. The following sample illustrates using the RadioButton control.


RadioButton1_cs.aspx

Web
<%@ Page Language="C#" %>
<script language="C#" runat="server">
 protected void SubmitBtn_Click( object sender, EventArgs e ) {
  if ( Radio1.Checked )
   Label1.Text = "You selected " + Radio1.Text;
  else if ( Radio2.Checked )
   Label1.Text = "You selected " + Radio2.Text;
  else if ( Radio3.Checked )
   Label1.Text = "You selected " + Radio3.Text;
 }
</script>

<html>
 <body> 
  <form runat="server">
   Select the type of installation you wish to perform:
   <asp:RadioButton id="Radio1" Text="Typical" Checked="True"
     GroupName="RadioGroup1" runat="server" />        
   This option ...  Requires 1.2 MB disk space.
   <asp:RadioButton id="Radio2" Text="Compact"
     GroupName="RadioGroup1" runat="server" />  
   This option ...  Requires 350 KB disk space.   
   <asp:RadioButton id="Radio3" runat="server" Text="Full"
     GroupName="RadioGroup1" />
   This option ...  Requires 4.3 MB disk space.
   <asp:button text="Submit" OnClick="SubmitBtn_Click" runat="server" />
   <asp:Label id="Label1" font-bold="true" runat="server" />
  </form>        
 </body>
</html>