在页上创建一个单选按钮。可将多个单选按钮分为一组以提供一组互相排斥的选项。
|
---|
<asp:RadioButton
????AccessKey="string"
????AutoPostBack="True|False"
????BackColor="color name|#dddddd"
????BorderColor="color name|#dddddd"
????BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
Inset|Outset"
????BorderWidth="size"
????CausesValidation="True|False"
????Checked="True|False"
????CssClass="string"
????Enabled="True|False"
????EnableTheming="True|False"
????EnableViewState="True|False"
????Font-Bold="True|False"
????Font-Italic="True|False"
????Font-Names="string"
????Font-Overline="True|False"
????Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
????Font-Strikeout="True|False"
????Font-Underline="True|False"
????ForeColor="color name|#dddddd"
????GroupName="string"
????Height="size"
????ID="string"
????OnCheckedChanged="CheckedChanged event handler"
????OnDataBinding="DataBinding event handler"
????OnDisposed="Disposed event handler"
????OnInit="Init event handler"
????OnLoad="Load event handler"
????OnPreRender="PreRender event handler"
????OnUnload="Unload event handler"
????runat="server"
????SkinID="string"
????Style="string"
????TabIndex="integer"
????Text="string"
????TextAlign="Left|Right"
????ToolTip="string"
????ValidationGroup="string"
????Visible="True|False"
????Width="size"
/> |
备注
示例
下面的示例演示如何使用 RadioButton 控件为用户提供一组互斥的选项。
Visual Basic? | 复制代码 |
---|
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script language="VB" runat="server">
Sub SubmitBtn_Click(Sender As Object, e As EventArgs)
If Radio1.Checked Then
Label1.Text = "You selected " & Radio1.Text
ElseIf Radio2.Checked Then
Label1.Text = "You selected " & Radio2.Text
ElseIf Radio3.Checked Then
Label1.Text = "You selected " & Radio3.Text
End If
End Sub
</script>
</head>
<body>
<h3>RadioButton Example</h3>
<form runat=server>
<h4>Select the type of installation you want to perform:</h4>
<asp:RadioButton id=Radio1 Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" /><br>
This option installs the features most typically used. <i>Requires 1.2 MB disk space.</i><p>
<asp:RadioButton id=Radio2 Text="Compact" GroupName="RadioGroup1" runat="server"/><br>
This option installs the minimum files required to run the product. <i>Requires 350 KB disk space.</i><p>
<asp:RadioButton id=Radio3 runat="server" Text="Full" GroupName="RadioGroup1" /><br>
This option installs all features for the product. <i>Requires 4.3 MB disk space.</i><p>
<asp:button text="Submit" OnClick="SubmitBtn_Click" runat=server/>
<asp:Label id=Label1 font-bold="true" runat="server" />
</form>
</body>
</html>
|
C#? | 复制代码 |
---|
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
void SubmitBtn_Click(Object Sender, EventArgs e) {
if (Radio1.Checked) {
Label1.Text = "You selected " + Radio1.Text;
}
else if (Radio2.Checked) {
Label1.Text = "You selected " + Radio2.Text;
}
else if (Radio3.Checked) {
Label1.Text = "You selected " + Radio3.Text;
}
}
</script>
</head>
<body>
<h3>RadioButton Example</h3>
<form runat=server>
<h4>Select the type of installation you want to perform:</h4>
<asp:RadioButton id=Radio1 Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" /><br>
This option installs the features most typically used. <i>Requires 1.2 MB disk space.</i><p>
<asp:RadioButton id=Radio2 Text="Compact" GroupName="RadioGroup1" runat="server"/><br>
This option installs the minimum files required to run the product. <i>Requires 350 KB disk space.</i><p>
<asp:RadioButton id=Radio3 runat="server" Text="Full" GroupName="RadioGroup1" /><br>
This option installs all features for the product. <i>Requires 4.3 MB disk space.</i><p>
<asp:button text="Submit" OnClick="SubmitBtn_Click" runat=server/>
<asp:Label id=Label1 font-bold="true" runat="server" />
</form>
</body>
</html>
|
请参见