将dbcontext对象分配给label

时间:2014-07-30 04:39:14

标签: c# dbcontext

我有一个表中的dbcontext对象,我试图分配给一个标签,但页面是空白的,标签没有显示输出。如何在按钮单击时成功分配标签,以便可以看到表格数据?我所指的对象是aMessage.highScoreEasy

    protected void myScoresButton_Click(object sender, EventArgs e)
    {
        int num = 2;
        int num1 = 5;
        int num2 = 6;
        easyScoreLabel.Text = num.ToString();
        mediumScoreLabel.Text = num1.ToString();
        hardScoreLabel.Text = num2.ToString();
        gameOverLabel.Visible = false;

        warningLabel.Visible = false;
        using (projectDBEntities1 dbcontext = new projectDBEntities1())
        {
            message aMessage = new message();
            endGameScoreLabel.Visible = true;
            int parsedScoreLabel = 3; 
            aMessage.highScoreEasy = parsedScoreLabel;

            if (!Int32.TryParse(easyScoreLabel.Text, out parsedScoreLabel))
            {
                // The parsing failed, maybe notify the user of an invalid value

                endGameScoreLabel.Text = aMessage.highScoreEasy.ToString();
                welcomeUsernameLabel.Text = "Welcome" + aMessage.userName;

                aMessage.userName = nameTextBox.Text;

                dbcontext.messages.Add(aMessage);
                dbcontext.SaveChanges();


            }

            GridView1.DataBind();
            GridView1.Visible = true;
        }
    }

0 个答案:

没有答案