ASP.NET 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 |
ASP.NET RadioButtonList CellPadding 属性
ASP.NET RadioButtonList CellPadding 属性用于设置或返回单元格边框与内容之间的像素数
该函数仅在 RepeatLayout 属性设置为 "Table" 时有效
语法
<asp:RadioButtonList
CellPadding="pixels"
runat="server">Some Content</asp:RadioButtonList>
属性 | 描述 |
---|---|
pixels | 规定单元格边框与内容之间的像素数 |
范例
下面的范例设置了 RadioButtonList 控件的 CellPadding 属性
<form runat="server">
<asp:RadioButtonList id="rb1" runat="server" CellPadding="15">Some content
</asp:RadioButtonList>
</form>
ASP.NET RadioButtonList CellSpacing 属性
ASP.NET RadioButtonList CellSpacing 属性用于获取或设置 RadioButtonList 中表格单元格之间的像素数
该函数仅在 RepeatLayout 属性设置为 "Table" 时有效(默认)
语法
<asp:RadioButtonList CellSpacing="pixels" runat="server">Some Content</asp:RadioButtonList>
属性 | 描述 |
---|---|
pixels | 规定表格单元格之间的像素数 |
范例
下面的范例设置了 RadioButtonList 控件的 CellSpacing 属性
<form runat="server">
<asp:RadioButtonList id="rb1" runat="server" CellSpacing="15">Some content
</asp:RadioButtonList>
</form>
ASP.NET RadioButtonList RepeatColumns 属性
ASP.NET RadioButtonList RepeatColumns 属性用于获取或设置当显示单选按钮列表时所用的列数
语法
<asp:RadioButtonList RepeatColumns="num" runat="server">Some Content</asp:RadioButtonList>
属性 | 描述 |
---|---|
num | 规定要显示的列数。默认是 "1" |
范例
下面的范例把 RadioButtonList 控件中的 RepeatColumns 属性设置为 "2"
<form runat="server">
<asp:RadioButtonList id="rb1" runat="server" RepeatColumns="2">Some content
</asp:RadioButtonList>
</form>
ASP.NET RadioButtonList RepeatDirection 属性
ASP.NET RadioButtonList RepeatDirection 属性用于获取或设置 RadioButtonList 中的项目垂直显示还是水平显示
语法
<asp:RadioButtonList RepeatDirection="mode" runat="server">Some Content</asp:RadioButtonList>
属性 | 描述 |
---|---|
mode | 规定 RadioButtonList 中项目的布局方向 可能的值: Horizontal - 项目水平显示 Vertical - 默认。项目垂直显示 |
范例
下面的范例设置了 RadioButtonList 控件的 RepeatDirection
<form runat="server">
<asp:RadioButtonList id="cb1" runat="server" RepeatDirection="Horizontal">Some content </asp:RadioButtonList>
</form>
ASP.NET RadioButtonList RepeatLayout 属性
ASP.NET RadioButtonList RepeatLayout 属性用于获取或设置如何显示 RadioButtonList 中的项目
语法
<asp:RadioButtonList RepeatLayout="mode" runat="server">Some Content</asp:RadioButtonList>
属性 | 描述 |
---|---|
mode | 规定 RadioButtonList 中的项目的布局 可能的值: Flow - 项目不显示在表格中 Table - 默认。项目显示在表格中 |
范例
下面的范例设置了 RadioButtonList 控件的 RepeatLayout
<form runat="server">
<asp:RadioButtonList id="rb1" runat="server" RepeatLayout="Flow">Some content</asp:RadioButtonList>
</form>
ASP.NET RadioButtonList TextAlign 属性
ASP.NET RadioButtonList TextAlign 属性用于获取或设置 RadioButtonList 项目的文本的文本对齐方式
语法
<asp:RadioButtonList TextAlign="align" runat="server">Some Content</asp:RadioButtonList>
属性 | 描述 |
---|---|
align | 规定列表项的文本对齐方式 可能的值: Left Right (默认) |
范例
下面的范例把 RadioButtonList 控件中的 TextAlign 属性设置为 "Left"
<form runat="server">
<asp:RadioButtonList id="rb1" runat="server" TextAlign="Left">Some content
</asp:RadioButtonList>
</form>
ListControl 标准属性
- AppendDataBoundItems
- AutoPostBack
- CausesValidation
- DataTextField
- DataTextFormatString
- DataValueField
- Items
- runat
- SelectedIndex
- SelectedItem
- SelectedValue
- TagKey
- Text
- ValidationGroup
- OnSelectedIndexChanged
ListControl 控件包括列表控件的所有基本功能
继承自此控件的控件包括:CheckBoxList, DropDownList, ListBox 以及 RadioButtonList 控件
如果想要查看完整描述,可以访问我们的 ListControl 标准属性
Web 控件标准属性
- AccessKey
- Attributes
- BackColor
- BorderColor
- BorderStyle
- BorderWidth
- CssClass
- Enabled
- Font
- EnableTheming
- ForeColor
- Height
- IsEnabled
- SkinID
- Style
- TabIndex
- ToolTip
- Width
如果想要查看完整描述,可以访问我们的 Web 控件标准属性
控件标准属性
- 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>
<meta charset="utf-8" />
<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>
范例中,我们声明了一个 RadioButtonList 控件,一个 Button 控件,以及一个 Label 控件然后,我们创建了一个事件句柄,当发生 Click 事件时,会把文本和被选项目显示在 Label 控件中