Data binding with the RadioButtonList Control : RadioButtonList « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblProduct.Text = rblProducts.SelectedItem.Text;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Show RadioButtonList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:RadioButtonList
        id="rblProducts"
        DataSourceID="srcProducts"
        DataTextField="Title"
        DataValueField="Id"
        RepeatColumns="3"
        Runat="server" />

    <asp:Button
        id="btnSubmit"
        Text="Submit"
        Runat="server" OnClick="btnSubmit_Click" />

    <hr />

    <asp:Label
        id="lblProduct"
        Runat="server" />

    <asp:SqlDataSource
        id="srcProducts"
        SelectCommand="SELECT Id, Title FROM Products"
        ConnectionString="<%$ ConnectionStrings:Products %>"
        Runat="server" />

    </div>
    </form>
</body>
</html>

            
File: Web.config

<configuration>
  <connectionStrings>
    <add name="Products" 
         connectionString="Data Source=.\SQLEXPRESS;
         AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />
  </connectionStrings>
</configuration>  

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.








3.14.RadioButtonList
3.14.1.Get selected item index from asp:RadioButtonList (VB.net)
3.14.2.Data binding with the RadioButtonList Control
3.14.3.A combination of bullet-list and radio-button list controls