Reputation: 1722
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
Upvotes: 0
Views: 104
Reputation: 1715
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.
Upvotes: 2