帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP.NET编程 >
RadioButton Web 控件
作者:佚名 发布时间:2005-04-02 来源:不详
 


    RadioButton Web 控件的基本功能即是HTML 控件的<Input Type="Radio">。它的外观及功能我们已经在HTML 控件中展示过了,不过它比HTML 控件的功能更强,其使用语法如下:

<ASP:RadioButton
Id="被程序代码所控制的名称"
Runat="Server"
AutoPostBack="True | False"
Checked="True | False"
GroupName="群组名称"
Text="标示控件的文字"
TextAlign="设定文字在控件的左边或右边"
OnCheckedChanged="事件程序名称"
/>


    下列范例码放置了两个RadioButton Web 控件,并在Page_Load 事件中设定控件的初始值。

<Html>
<Form Id="Form1" Runat="Server">
<ASP:RadioButton Id="Radio1" Text="第一个Radio" Runat="Server"/><br>
<ASP:RadioButton Id="Radio2" Text="第二个Radio" Runat="Server"/>
</Form>
<Script Language="VB" Runat="Server">
Sub Page_Load(Sender As Object,e As Eventargs)
Radio2.Checked="True" '让第二个Radio 变成选取
End Sub
</Script>
</Html>


    这个范例中RadioButton 是两个独立的Web 控件,若我们希望在一群RadioButton Web 控制中只能选择一个时,只要将它们的GroupName 设为同一个即可。此时我们只能在这些RadioButtonWeb 控件中选择其中一个。下列程序代码范例中,我们限制了只能在三个RadioButton Web 控件中选择一个项目:

<Html>
<Form Id="Form1" Runat="Server">
<ASP:RadioButton Id="Radio1" Text="RadioButton1" GroupName="Group1"
Checked="True"
Runat="Server"/><Br>
<ASP:RadioButton Id="Radio2" Text="RadioButton2" GroupName="Group1"
Runat="Server"/><Br>
<ASP:RadioButton Id="Radio3" Text="RadioButton3" GroupName="Group1"
Runat="Server"/><P>
<ASP:Button Id="Button1" Text="Check" OnClick="Button1_Click"
Runat="Server"/><P>
<ASP:Label Id="Label1" Runat="Server"/>
</Form>
<Script Language="VB" Runat="Server">
Sub Button1_Click(Sender As Object,e As Eventargs)
If Radio1.Checked Then Label1.Text="你选择了RadioButton1"
If Radio2.Checked Then Label1.Text="你选择了RadioButton2"
If Radio3.Checked Then Label1.Text="你选择了RadioButton3"
End Sub
</Script>
</Html>



AutoPostBack 属性以及CheckedChanged 事件
    RadioButton Web 控件有CheckedChanged 事件,这个事件是在当RadioButton 控件的选择状态发生改变时触发;要触发这个事件,必须把AutoPostBack 属性设为Ture 才生效。下列程序代码范例将上述程序改成不需要按下按钮,只要使用者选择的项目不一样就会触发
CheckedChanged 事件:

<Html>
<Form Id="Form1" Runat="Server">
<ASP:RadioButton Id="Radio1" Text="RadioButton1" GroupName="Group1"
AutoPostBack="True"
OnCheckedChanged="Check_Clicked"
Runat="Server"/><Br>
<ASP:RadioButton Id="Radio2" Text="RadioButton2" GroupName="Group1"
AutoPostBack="True"
OnCheckedChanged="Check_Clicked"
Runat="Server"/><p>
<ASP:Label Id="Label1" Runat="Server"/>
</Form>
<Script Language="VB" Runat="Server">
Sub Check_Clicked(Sender As Object,e As Eventargs)
If Radio1.Checked Then Label1.Text="Radio1"
If Radio2.Checked Then Label1.Text="Radio2"
End Sub
</Script>
</Html>


  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·RadioButtonList Web 控件  (2005-04-02)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·放眼未来 帝国近期将有重大举措!
·PHPWind6.3.2版通行证发布
·帝国备份王2008版正式发布
·帝国备份王2008版发布
·phpcms2007转帝国CMS5.0程序发布
·dedecms5.1转帝国CMS5.0程序发布
·帝国网站管理系统V5.0商业购买说明
   类别最新
·ASP.NET中为DataGrid添加合计字段
·.text urlRewrite介绍
·利用 ASP.NET 的内置功能抵御 Web
·ASP.NET Cache
·用 WebClient.UploadData 方法 上载
·ASP.NET 程序设计-序
·什么是客户端/伺服端(Client/Serve
·因特网应用程序的开发
·网页的种类
·.NET Framework-Microsoft Visual
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统