0

我有一个单选按钮

 <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>");

        }
    }

问题是即使我已经检查/选择了 LMradiobutton 代码仍然在里面,if(AMRadioButton.Checked = true)这不是我想要的,当然,当我勾选 LMradiobutton 时,代码应该else if (LMRadioButton.Checked = true)在 amradiobutton.Checked 中没有。

我想念什么吗?请帮忙

4

1 回答 1

2

利用

if(AMRadioButton.Checked == true) 

或者

else if (LMRadioButton.Checked == true)

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

赋值时使用 =。

您正在为已检查的属性分配值,该属性将始终返回 true。

于 2013-09-30T05:13:13.067 回答