RadioButton 和 RadioButtonList 比较

第一次接触RadioBttonList时候,觉得这个控件完全可以取代RadioButton,操作更加简便。直到今天,完成了一个小小的功能,才发现,尺有所短不是瞎掰的。

需求如下:

Add Proration Rate radio buttons.

  • Radio button for a fixed rate
    • Selected by default
    • Meaning using HR user for calculation
  • Radio button for Based on old logic

亲爱的Radio之间隔了其他控件,于是,List毫无用武之地。只能定义Group将Radio绑在一组内。

前台

复制代码
 1 <table>
 2                                         <tr>
 3                                             <td class="font12 bold dkgray right" width="150">
 4                                                 &nbsp;&nbsp;<asp:Label runat="server" ID="Label20">Proation Rate:</asp:Label>
 5                                             </td>
 6                                             <td class="font12 bold dkgray" width="800">
 7                                                 <asp:RadioButton ID="rbFixed" runat="server" Checked="True" 
 8                                                     GroupName="Proation" AutoPostBack="True" 
 9                                                     oncheckedchanged="rbFixed_CheckedChanged" />
10                                                 <asp:TextBox ID="txtFixedRate" runat="server" MaxLength="7"></asp:TextBox>
11                                                 <asp:Label runat="server" ID="Label21">(A fixed rate, int the format decimal number)</asp:Label>
12                                                   <asp:Label runat="server" ID="lblProationRate" ForeColor="red" ></asp:Label>
13                                                 <br />
14                                                 <asp:RadioButton ID="rbOld" runat="server" GroupName="Proation" 
15                                                     oncheckedchanged="rbOld_CheckedChanged" AutoPostBack="True" />
16                                                 <asp:Label runat="server" ID="Label22">Based on old logic ((Effective Date - Last increase Date - LOA days )/364)</asp:Label>
17                                             </td>
18                                         </tr>
19                                     </table>
View Code
复制代码

后台的话 监听事件就会麻烦一点点。不知道对不对呢,明天才能见分晓。

后台

复制代码
        protected void rbOld_CheckedChanged(object sender, EventArgs e)
        {
            if (rbOld.Checked) 
            { 
                txtFixedRate.Text = string.Empty;
                txtFixedRate.Enabled = false;
                lblProationRate.Text = string.Empty;
            }
             
        }

        protected void rbFixed_CheckedChanged(object sender, EventArgs e)
        {
            if (rbFixed.Checked) txtFixedRate.Enabled = true;
        }
View Code
复制代码

 另 清楚RadiobuttonList所有选中项的方法:   RadioButtonList1.ClearSelection();

posted @   Genie in the bottle  阅读(1069)  评论(0编辑  收藏  举报
编辑推荐:
· 为什么构造函数需要尽可能的简单
· 探秘 MySQL 索引底层原理,解锁数据库优化的关键密码(下)
· 大模型 Token 究竟是啥:图解大模型Token
· 35岁程序员的中年求职记:四次碰壁后的深度反思
· 继承的思维:从思维模式到架构设计的深度解析
阅读排行:
· 【保姆级教程】windows 安装 docker 全流程
· 基于Docker+DeepSeek+Dify :搭建企业级本地私有化知识库超详细教程
· 由 MCP 官方推出的 C# SDK,使 .NET 应用程序、服务和库能够快速实现与 MCP 客户端
· 电商平台中订单未支付过期如何实现自动关单?
· 上周热点回顾(3.31-4.6)
点击右上角即可分享
微信分享提示