Home

Web Control: The Radio Button List

 

Radio Button List Fundamentals

 

Introduction

To assist you with creating a group of radio buttons, you can use the RadioButtonList control. This control is implemented by the RadioButtonList class defined in the System.Web.UI.WebControls namespace of the System.Web.dll assembly.

 

Creating a Radio Button List

To visually create a radio button list, from the Standard section of the Toolbox, you can drag RadioButtonList and drop it on the form. You would be asked to create each item of the group. To do this, you can click its arrow button and click Edit Items, then use the ListItem Collection Editor:

ListItem Collection Editor

If the radio button list was already created, to access the ListItem Collection Editor, click the radio button list on the form. In the Properties window, click Items and click browse button.

To manually create a group of radio buttons, create an <asp:RadioButtonList> tag on the form:

<%@ Page Language="C#" %>
<html>
<head>

<title>Exercise</title>
</head>
<body>

<h3>Exercise</h3>

<form id="frmRealEstate" method="post" runat="server">
  <asp:RadioButtonList id="Genders" runat="server"></asp:RadioButtonList>
</form>

</body>
</html>

To create each item of the group,

  • If you are using the ListItem Collection Editor, click Add
  • If you are working manually, between the opening and the closing tags, create an asp:ListItem tag with its own starting and closing tags:
<%@ Page Language="C#" %>
<html>
<head>

<title>Exercise</title>
</head>
<body>
 
<form id="frmRealEstate" method="post" runat="server">
  <asp:RadioButtonList id="Genders" runat="server">
    <asp:ListItem></asp:ListItem>
  </asp:RadioButtonList>
</form>

</body>
</html>

Characteristics of a Radio Button List

 

The Captions of Radio Buttons

Obvious each radio button should display text to show what it is used for:

  • If you are working in the ListItem Collection Editor, on the left side, click an item. On the right side, click Text and type the desired string
  • If you are working manually, to specify the caption of a radio button, type its string between the beginning and the ending tags
 
 
 
 

Here are examples:

<%@ Page Language="C#" %>
<html>
<head>

<title>Exercise</title>
</head>
<body>

<form id="frmRealEstate" method="post" runat="server">
  <asp:RadioButtonList id="Genders" runat="server">
    <asp:ListItem>Male</asp:ListItem>
    <asp:ListItem>Female</asp:ListItem>
    <asp:ListItem>Unknown</asp:ListItem>
  </asp:RadioButtonList>
</form>

</body>
</html>

This would produce:

Radio Button

The Caption Alignment of a Radio Button

By default, the captions of the radio buttons are positioned on the right side of their round boxes. This characteristic is controlled by the TextAlign attribute of the RadioButtonList control and whose default value is Right. If you want the captions to be positioned to the left, assign the Left string to this attribute. Here is an example:

<%@ Page Language="C#" %>
<html>
<head>

<title>Exercise</title>
</head>
<body>

<form id="frmRealEstate" method="post" runat="server">
  <asp:RadioButtonList id="Genders" TextAlign="Left" runat="server">
    <asp:ListItem>Male</asp:ListItem>
    <asp:ListItem>Female</asp:ListItem>
    <asp:ListItem>Unknown</asp:ListItem>
  </asp:RadioButtonList>
</form>

</body>
</html>

This would produce:

Radio Button List

 
 
   
 

Home Copyright © 2009-2016, FunctionX, Inc.