C# dbcontext数据未正确分配到标签
我为标签onclick分配了一个dbcontext对象。问题是dbcontext对象没有显示在web浏览器中。相反,什么都没有。它应该显示计数器的int值。如何分配并在标签中显示它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;
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文件