简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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