JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the RadioButtonList Class

The RadioButtonList control lets you display a list of radio buttons. Here is the inheritance hierarchy of this class:

Object
   Control
      WebControl
         ListControl
            RadioButtonList

To determine which item is selected in a radio button control, you can test the SelectedItem property of the list. You also can determine the index of the selected item with the SelectedIndex property. Each item in the radio button list's Items collection (inherited from the ListControl class) is an object of the ListItem class (see "Using the ListItem Class" in this chapter), and you can use the ListItem class's Value, Text, and Selected properties to work with the radio buttons in the list like this: RadioButtonList1.Items(5).Selected.

You can customize how the list is displayed using the RepeatLayout and RepeatDirection properties. If RepeatLayout is set to RepeatLayout.Table (which is the default), the list is drawn in an HTML table. If it is set to RepeatLayout.Flow, on the other hand, the list is drawn without a table. And by default, RepeatDirection is set to RepeatDirection.Vertical. Setting this property to RepeatDirection.Horizontal draws the list horizontally.

You can find the notable public properties of RadioButtonList objects in Table 16.13, the notable methods in Table 16.14, and the notable public events in Table 16.15. Note that as with other Web server controls, I am not listing the notable properties, methods, and events this class inherits from the Control and WebControl classes; you can find them in Tables 15.1 to 15.5 in Chapter 15. This class also inherits from the ListControl class you can find the notable public properties of ListControl objects in Table 16.4, and their notable public events in Table 16.5. (This class has no non-inherited methods.)

Table 16.13: Noteworthy public properties of RadioButtonList objects.

Property

Means

CellPadding

Gets/sets the distance between the radio button and the table cell that contains it, in pixels.

CellSpacing

Gets/sets the distance between the table cells the radio buttons are displayed in, in pixels.

RepeatColumns

Gets/sets the number of displayed columns in the radio button list.

RepeatDirection

Gets/sets the display direction of radio buttons.

RepeatLayout

Gets/sets the radio button layout.

TextAlign

Gets/sets the radio button's caption text alignment.

Table 16.14: Noteworthy public methods of RadioButtonList objects.

Method

Means

DataBind

Binds a radio button list to a data source.

Table 16.15: Noteworthy public events of RadioButtonList objects.

Event

Means

SelectedIndexChanged

Occurs when the selection in the radio button list changes.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor