简体   繁体   English

单选按钮选中不触发

[英]Radio Button Checked doesn't Trigger right

I have a radio button 我有一个单选按钮

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

and i have a code behind 我有一个代码

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

        }
    }

the problem is even though i have checked/selected the the LMradiobutton the code still goes inside the if(AMRadioButton.Checked = true) which is not what i want, ofcourse when i ticked the LMradiobutton the code supposed to be else if (LMRadioButton.Checked = true) in here no in the amradiobutton.Checked. 问题是即使我已经检查/选择LMradiobutton代码仍然进入if(AMRadioButton.Checked = true)这不是我想要的,当然我勾选LMradiobutton代码应该是else if (LMRadioButton.Checked = true)这里没有amradiobutton.Checked。

do i miss something? 我错过了什么吗? please help 请帮忙

Use 采用

if(AMRadioButton.Checked == true) 

or 要么

else if (LMRadioButton.Checked == true)

Use == for checking conditions or as compare operator 使用==检查条件或比较运算符

Use = when assigning values. 分配值时使用=。

You are assigning value to checked property which will always return true. 您正在为已检查的属性赋值,该属性将始终返回true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM