我有一个单选按钮
<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。
答案 0 :(得分:2)
使用
if(AMRadioButton.Checked == true)
或
else if (LMRadioButton.Checked == true)
使用==检查条件或比较运算符
在分配值时使用=。
您正在为checked属性赋值,该属性将始终返回true。