RadioButton List Control in ASP.NET

Introduction & Demonstration

The RadioButtonList control works like the DropDownList control but it enables a user to select only one list item at a time. The RadioButttonList control displays a list of radio buttons that can be arranged either horizontally or vertically.

The page given below illustrates how we use the RadioButtonList control to display a list of products titles.


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""">

<script runat="server">

       Protected Sub btnSubmit_Click(ByVal sender As ObjectByVal e As EventArgs)
        lblProduct.Text = rblProducts.SelectedItem.Text
    End Sub

html xmlns="" >
<head id="Head1" runat="server">
    <form id="form1" runat="server">


        Runat="server" />

        Runat="server" OnClick="btnSubmit_Click" />

    <hr />

        Runat="server" />

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>"
            ProviderName="<%$ ConnectionStrings:DatabaseConnectionString1.ProviderName %>"
            SelectCommand="SELECT [ID], [TITLE] FROM [PRO_LIST]"></asp:SqlDataSource>


In above example, the radio buttons are rendered in a three-column layout. The RadioButtonList control includes three properties that have an effect on its layout:

  • RepeatColumns The number of columns of radio buttons to display.
  • RepeatDirection The direction that the radio buttons are repeated. Possible values are Horizontal and Vertical.
  • RepeatLayout Determines whether the radio buttons are displayed in an HTML table. Possible values are Table and Flow.

By default, the radio buttons rendered by the RadioButtonList control are rendered in an HTML table. If we set the RepeatLayout property to the value Flow, then the radio buttons are not rendered in a table. Even when the RadioButtonList renders its items in Flow layout mode, we can specify multiple columns.


Up Next
    Ebook Download
    View all
    View all