简体   繁体   English

CheckBox没有更改为Checked

[英]CheckBox is not changing to Checked

I have some logic that is supposed to read whether a column in a database is supposed to be 1 or 0, representing true or false. 我有一些逻辑可以读取数据库中的列应该是1还是0,代表true或false。

I've gone through it with the debugger and the if statement evaluates to true, so surely that would mean that the checkbox should appear to be checked? 我已经使用调试器进行了遍历,并且if语句的评估结果为true,因此,这肯定意味着应该选中该复选框吗?

int QuestionID = Convert.ToInt32(ddQuestions.SelectedItem.Text);

using (SqlDataReader dr = SQLData.checkchkbx(QuestionID))
{
    if (dr.HasRows)
    {
        while (dr.Read())
        {
            string TRUEorFALSE = dr["TRUEorFALSE"].ToString();
            int trueorfalse = Convert.ToInt32(TRUEorFALSE);

            if (trueorfalse == 1)
            {
                chkbxAnswer1.Checked=true;
            }
        }
    }
}

Am I missing something here? 我在这里想念什么吗?

Ok, I managed to solve it by changing the "1" in the if statement to "True", as follows 好的,我设法通过将if语句中的“ 1”更改为“ True”,如下所示

 using (SqlDataReader dr = SQLData.checkchkbx(QuestionID))
            {
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        string TRUEorFALSE = dr["TRUEorFALSE"].ToString();
                        if (TRUEorFALSE == "True")
                        {
                            chkbxAnswer1.Checked = true;
                        }
                    }
                }
            }

For some reason (I still don't know why) somewhere, the TRUEorFALSE column in the database, despite being populated with 1s and 0s, returns "True"s and "False"s, which is kinda cool, but I have no idea why... 由于某些原因(我仍然不知道为什么),尽管数据库中的TRUEorFALSE列填充了1和0,但仍返回“ True”和“ False”,这有点酷,但是我不知道为什么...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM