Working with the RadioButtonList Control


Working with the RadioButtonList Control

The RadioButtonList control, like the DropDownList control, 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 in Listing 10.10 illustrates how you can use the RadioButtonList control to display a list of movie titles (see Figure 10.9).

Figure 10.9. Displaying list items with the RadioButtonList control.


Listing 10.10. ShowRadioButtonList.aspx

<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server">     Protected  Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)         lblMovie.Text = rblMovies.SelectedItem.Text     End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head  runat="server">     <title>Show RadioButtonList</title> </head> <body>     <form  runat="server">     <div>     <asp:RadioButtonList                  DataSource         DataTextField="Title"         DataValueField="Id"         RepeatColumns="3"         Runat="server" />     <asp:Button                  Text="Submit"         Runat="server" OnClick="btnSubmit_Click" />     <hr />     <asp:Label                  Runat="server" />     <asp:SqlDataSource                  SelectCommand="SELECT Id, Title FROM Movies"         ConnectionString="<%$ ConnectionStrings:Movies %>"         Runat="server" />     </div>     </form> </body> </html>

In Listing 10.10, 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 you 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, you can specify multiple columns.




ASP. NET 2.0 Unleashed
ASP.NET 2.0 Unleashed
ISBN: 0672328232
EAN: 2147483647
Year: 2006
Pages: 276

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net