代码之家  ›  专栏  ›  技术社区  ›  Albert Laure

选中的单选按钮未正确触发

  •  0
  • Albert Laure  · 技术社区  · 11 年前

    我有一个收音机按钮

     <asp:RadioButton ID="AMRadioButton" runat="server" AutoPostBack="True" GroupName="TypeGroup"
                                    OnCheckedChanged="AMRadioButton_CheckedChanged" Text="Accounting Date" />
                                <asp:RadioButton ID="LMRadioButton" runat="server" AutoPostBack="True" GroupName="TypeGroup"
                                    OnCheckedChanged="LMRadioButton_CheckedChanged" Text="Loan Date" />
    

    我有一个密码

     protected void AddButton_Click(object sender, EventArgs e)
        {
            if (AMRadioButton.Checked = true)
            {
                prenda.Bcode = BranchCodetxtbox.Text;
                prenda.AccountingMonth = YearDropDownList.SelectedValue + "/" + MonthDropDownList.SelectedValue;
                prenda.Jprincipal = Convert.ToDecimal(JewelryTextBox.Text);
                prenda.Aprincipal =  Convert.ToDecimal(ApplianceTextBox.Text);
                prenda.Cprincipal =  Convert.ToDecimal(CellphoneTextBox.Text);
                user.UserID = Session["UserID"].ToString();
                servs.UploadPrendaAM(prenda, user);
                Session["Count"] = "1";
                Response.Write("<script language='javascript'>window.alert('Success!');window.location='DataEntryPage.aspx';</script>");
    
            }
            else if (LMRadioButton.Checked = true)
            {
                prenda.Bcode = BranchCodetxtbox.Text;
                prenda.LoanMonth = YearDropDownList.SelectedValue + "/" + MonthDropDownList.SelectedValue;
                prenda.Jprincipal =  Convert.ToDecimal(JewelryTextBox.Text);
                prenda.Aprincipal =  Convert.ToDecimal(ApplianceTextBox.Text);
                prenda.Cprincipal =  Convert.ToDecimal(CellphoneTextBox.Text);
                user.UserID = Session["UserID"].ToString();
                servs.UploadPrendaLM(prenda, user);
                Session["Count"] = "1";
                Response.Write("<script language='javascript'>window.alert('Success!');window.location='DataEntryPage.aspx';</script>");
    
            }
        }
    

    问题是,即使我已经检查/选择了LMradio按钮,代码仍然会进入 if(AMRadioButton.Checked = true) 这不是我想要的,当然,当我勾选LMradio按钮时,代码应该是 else if (LMRadioButton.Checked = true) 在这里不在amradiobutton。检查。

    我错过什么了吗?请帮忙

    1 回复  |  直到 11 年前
        1
  •  2
  •   Nikhil Chavan    11 年前

    使用

    if(AMRadioButton.Checked == true) 
    

    else if (LMRadioButton.Checked == true)
    

    使用==检查条件或用作比较运算符

    指定值时使用=。

    您正在为选中的属性赋值,该属性将始终返回true。