2013-09-30 18 views
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在這裏沒有在amradiobutton.Checked應該是else if (LMRadioButton.Checked = true)的代碼。

做我錯過了什麼?請幫助

+0

似乎兩個單選按鈕觸發不同的事件(AMRadioButton_CheckedChanged和LMRadioButton_CheckedChanged)。你檢查過這些事件嗎?這裏發佈的代碼來自不同的事件處理程序(addbutton_click)。如果他們被選中 – iceheaven31

+0

IM只是測試。 – user2705620

回答

2

使用

if(AMRadioButton.Checked == true) 

else if (LMRadioButton.Checked == true) 

使用==檢查條件或比較操作

使用賦值時=。

你要檢查屬性,它總是返回真值分配。

+0

太棒了!有效。似乎基本面並沒有陷入我的嘿呵謝謝!生病接受並儘快給予好評你,我可以:) – user2705620

+0

歡迎,它發生...... –