Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# dbcontext数据未正确分配到标签_C#_Dbcontext - Fatal编程技术网

C# dbcontext数据未正确分配到标签

C# dbcontext数据未正确分配到标签,c#,dbcontext,C#,Dbcontext,我为标签onclick分配了一个dbcontext对象。问题是dbcontext对象没有显示在web浏览器中。相反,什么都没有。它应该显示计数器的int值。如何分配并在标签中显示它 protected void startOverButton_Click(object sender, EventArgs e) { gameOverLabel.Visible = false; answerStatus.Visible = true;

我为标签onclick分配了一个dbcontext对象。问题是dbcontext对象没有显示在web浏览器中。相反,什么都没有。它应该显示计数器的int值。如何分配并在标签中显示它

    protected void startOverButton_Click(object sender, EventArgs e)
    {
        gameOverLabel.Visible = false;


        answerStatus.Visible = true;
        Session["AttemptCount"] = 0;
        Session["strikes"] = 0;

        int answer = randomNumber1 + randomNumber2;
       counter = (int)Session["AttemptCount"];
        int strikeCounter = (int)Session["strikes"];

        if (mathAnswerTextBox.Text == answer.ToString())
        {
            counter += 5;

            Session["AttemptCount"] = counter;

            answerStatus.Text = "Correct!";
            warningLabel.Visible = true; ;

            scoreLabel.Text = "Score: " + counter.ToString();
            randomNumber1 = random.Next(0, 50);
            randomNumber2 = random.Next(0, 50);
            num1Label.Text = Convert.ToString(randomNumber1);//add this line 
            num2Label.Text = Convert.ToString(randomNumber2); //and this line
            num1Label.Visible = true;
            num2Label.Visible = true;
            mathAnswerTextBox.Visible = true;

            submitAnswerButton.Visible = true;
        }

您在哪里定义GridView1的数据源?除非Im缺少某些内容,否则您是无源绑定的。我更新了上面的代码以显示完整的.aspx.cs文件