radiobutton的应用

本文提供了一个使用RadioButton的示例代码,并介绍了如何处理RadioButton选择变化的情况。此外,还讨论了在通过数据绑定创建RadioButton时遇到的groupName一致性问题及解决方法。
ContractedBlock.gifExpandedBlockStart.gifCode
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
 
<head runat="server">
    
<title>RadioButton Example</title>
<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 id="form1" 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><br />

         
<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><br />

         
<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><br />

         
<asp:button ID="Button1" text="Submit" OnClick="SubmitBtn_Click" runat="server"/>

         
<asp:Label id="Label1" font-bold="true" runat="server" />

     
</form>

 
</body>
 
</html>


checked发生变化时触发onCheckedChanged事件

上面的例子中并没有申明oncheckedchanged事件,而在bottonclick中来分析radiobutton组中的checked情况

常见的是这种方式

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

下面说下通过数据绑定控件生成一系列radiobutton时出现的问题

所有的groupname不是一致的,因此需要些个onclick()函数调用javascript

注意onclick()不是radiobutton的事件

ContractedBlock.gifExpandedBlockStart.gifCode
 function CancelSelect(obj)
 {
      elem
=obj.form.elements;  
      
for(i=0;i<elem.length;i++)
      {
          
if (elem[i].type=="radio" && elem[i].id != obj.id)
          {
              elem[i].
checked = false;
          }
      }
}


 

转载于:https://www.cnblogs.com/tangjian/archive/2009/02/22/1395855.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值