Mega Code Archive

 
Categories / ASP.Net Tutorial / ASP Net Controls
 

Data binding with the RadioButtonList Control

<%@ 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.