复选框不返回选中的值

时间:2017-01-31 04:43:39

标签: c# asp.net

我有3个复选框。

this is my design view

我的代码背后:

int e_n_SG = 0;
int e_n_PR = 0;
int e_n_FG = 0;
if (natSG.Checked)
{
    e_n_SG = 1;
}
if (natPR.Checked)
{
    e_n_PR = 1;
}

if (natFG.Checked)
{
    e_n_FG = 1;
}

addScholarship updated1 = new addScholarship(agg, gender, criteria, id1, e_n_SG, e_n_PR, e_n_FG);

update1[0] = updated1;

当我检查外国人时,当我尝试检索数据时,它将返回新加坡人。当我检查新加坡时,它什么也没有显示。我试图调试,我注意到没有检索到e_n_FG。 :

enter image description here

我的构造函数:

public addScholarship(int Aggregate, string Gender, string OtherDetails, int Scholarship_id, int e_n_SG, int e_n_PR, int e_n_FG)
{
    this.Aggregate = Aggregate;
    this.Gender = Gender;
    this.OtherDetails = OtherDetails;
    this.Scholarship_id = Scholarship_id;
    this.e_n_SG = e_n_SG;
    this.e_n_PR = e_n_PR;
    this.e_n_SG = e_n_FG;
}

有人可以建议我吗?

2 个答案:

答案 0 :(得分:0)

在控制中使用 对事件

使用AutoPostBack =“true”
 <asp:CheckBox ID="chkBox" runat="server" AutoPostBack="true" />

答案 1 :(得分:0)

public addScholarship(int Aggregate, string Gender, string OtherDetails, int Scholarship_id, int e_n_SG, int e_n_PR, int e_n_FG)
    {
        this.Aggregate = Aggregate;
        this.Gender = Gender;
        this.OtherDetails = OtherDetails;
        this.Scholarship_id = Scholarship_id;
        this.e_n_SG = e_n_SG;
        this.e_n_PR = e_n_PR;
        this.e_n_SG = e_n_FG; // <--- it should be this.e_n_FG = e_n_FG;
    }