簡體   English   中英

單選按鈕選中不觸發

[英]Radio Button Checked doesn't Trigger right

我有一個單選按鈕

 <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。

我錯過了什么嗎? 請幫忙

采用

if(AMRadioButton.Checked == true) 

要么

else if (LMRadioButton.Checked == true)

使用==檢查條件或比較運算符

分配值時使用=。

您正在為已檢查的屬性賦值,該屬性將始終返回true。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM