|
RadioButton 控件用于顯示單選按鈕。與HTML控件的 <Input Type="Radio">的功能相同。單選控件的選擇可能性不一定是兩種,只要是有限種可能性,并且只能從中選擇一種結(jié)果,原則上都可以用單選控件(RadioButton)來(lái)實(shí)現(xiàn)。 提示:如需創(chuàng)建一系列使用數(shù)據(jù)綁定的單選按鈕,請(qǐng)使用 RadioButtonList 控件! 一、RadioButton 控件屬性 二、使用語(yǔ)法 <ASP:RadioButton Id="控件名稱" Runat="Server" AutoPostBack="True | False" Checked="True | False" GroupName="群組名稱" Text="標(biāo)示控件的文字" TextAlign="設(shè)定文字在控件的左邊或右邊" OnCheckedChanged="事件程序名稱" /> 三、使用實(shí)例 RadioButton中,唯一要說(shuō)的說(shuō)是GroupName,當(dāng)有這個(gè)屬性時(shí),可以指定同一個(gè)容器中的組,如果沒(méi)有這個(gè)參屬性,默認(rèn)當(dāng)所有RadioButton都以這個(gè)容器為一組。 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() + "."; } |
|
|
來(lái)自: 悟靜 > 《.net和asp.net》