RadioButtonList 控件用于创建单选按钮组。
RadioButtonList 控件中的每个可选项是通过 ListItem 元素来定义的!
提示:该控件支持数据绑定!
属性 | 描述 | .NET |
---|---|---|
CellPadding | 单元格边框与内容之间的像素数。 | 1.0 |
CellSpacing | 表格单元格之间的像素数。 | 1.0 |
RepeatColumns | 当显示单选按钮组时要使用的列数。 | 1.0 |
RepeatDirection | 规定单选按钮组应水平重复还是垂直重复。 | 1.0 |
RepeatLayout | 单选按钮组的布局。 | 1.0 |
runat | 规定该控件是服务器控件。必须设置为 "server"。 | 1.0 |
TextAlign | 文本应出现在单选按钮的哪一侧(左侧还是右侧)。 | 1.0 |
- AppendDataBoundItems, AutoPostBack, CausesValidation, DataTextField, DataTextFormatString, DataValueField, Items, runat, SelectedIndex, SelectedItem, SelectedValue, TagKey, Text, ValidationGroup, OnSelectedIndexChanged
The ListControl control covers all the base functions for list controls. Controls that inherits from this control include the CheckBoxList, DropDownList, ListBox, and RadioButtonList controls.
- AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width
- AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site, TemplateControl, TemplateSourceDirectory, UniqueID, Visible
RadiobuttonList
- <script runat="server">
- Sub submit(sender As Object, e As EventArgs)
- label1.Text="You selected " & radiolist1.SelectedItem.Text
- End Sub
- </script>
- <!DOCTYPE html>
- <html>
- <body>
- <form runat="server">
- <asp:RadioButtonList id="radiolist1" runat="server">
- <asp:ListItem selected="true">Item 1</asp:ListItem>
- <asp:ListItem>Item 2</asp:ListItem>
- <asp:ListItem>Item 3</asp:ListItem>
- <asp:ListItem>Item 4</asp:ListItem>
- </asp:RadioButtonList>
- <br>
- <asp:Button text="Submit" OnClick="submit" runat="server"/>
- <p><asp:Label id="Label1" runat="server"/></p>
- </form>
- </body>
- </html>
在本例中,我们在 .aspx 文件中声明了一个 RadioButtonList 控件,一个 Button 控件,以及一个 Label 控件。然后,我们创建了一个事件句柄,当发生 Click 事件时,会把文本和被选项目显示在 Label 控件中。