RadioButton 控件用于显示单选按钮。与HTML控件的 <Input Type="Radio">的功能相同。单选控件的选择可能性不一定是两种,只要是有限种可能性,并且只能从中选择一种结果,原则上都可以用单选控件(RadioButton)来实现。 提示:如需创建一系列使用数据绑定的单选按钮,请使用 RadioButtonList 控件! 一、RadioButton 控件属性 二、使用语法 <ASP:RadioButton Id="控件名称" Runat="Server" AutoPostBack="True | False" Checked="True | False" GroupName="群组名称" Text="标示控件的文字" TextAlign="设定文字在控件的左边或右边" OnCheckedChanged="事件程序名称" /> 三、使用实例 RadioButton中,唯一要说的说是GroupName,当有这个属性时,可以指定同一个容器中的组,如果没有这个参属性,默认当所有RadioButton都以这个容器为一组。 XAML代码: >RadioButton</TextBlock> <DockPanel Margin="10,57.56,3,38.338" Grid.Column="0"/> <DockPanel Margin="10,46.197,3,24.261" Grid.Column="0"> <TextBlock Name="txtb" FontSize="12">Click a radio button.</TextBlock> <StackPanel> <RadioButton Name="rb1" Checked="WriteText2">Yes</RadioButton> <RadioButton Name="rb2" Checked="WriteText2">No</RadioButton> <RadioButton Name="rb3" Checked="WriteText2">No opinion</RadioButton> </StackPanel> </DockPanel> <DockPanel Margin="10,0,3,0" Grid.Column="0" VerticalAlignment="Bottom" Height="63.84"> <TextBlock FontSize="12">Choose color and number.</TextBlock> <StackPanel> <RadioButton GroupName="colorgrp">Red</RadioButton> <RadioButton GroupName="colorgrp">Blue</RadioButton> <RadioButton GroupName="numgrp">1</RadioButton> <RadioButton GroupName="numgrp">2</RadioButton> </StackPanel> </DockPanel> CS代码: void WriteText2(object sender, RoutedEventArgs e) { RadioButton li = (sender as RadioButton); txtb.Text = "You clicked " + li.Content.ToString() + "."; } |
|
来自: 悟静 > 《.net和asp.net》