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

RadioButton 和 RadioButtonList 比较_第1张图片

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

前台

 1  2 3 61819
class="font12 bold dkgray right" width="150"> 4   "server" ID="Label20">Proation Rate: 5 class="font12 bold dkgray" width="800"> 7 "rbFixed" runat="server" Checked="True" 8 GroupName="Proation" AutoPostBack="True" 9 oncheckedchanged="rbFixed_CheckedChanged" /> 10 "txtFixedRate" runat="server" MaxLength="7"> 11 "server" ID="Label21">(A fixed rate, int the format decimal number) 12 "server" ID="lblProationRate" ForeColor="red" > 13
14 "rbOld" runat="server" GroupName="Proation" 15 oncheckedchanged="rbOld_CheckedChanged" AutoPostBack="True" /> 16 "server" ID="Label22">Based on old logic ((Effective Date - Last increase Date - LOA days )/364) 17
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();

转载于:https://www.cnblogs.com/coderinprague/p/3430149.html

你可能感兴趣的:(RadioButton 和 RadioButtonList 比较)