0

下面的代码允许我在我选择的行中添加 +1,但我的问题是,一旦它被更新,“值”的新值就不会被接受

 public void InspireMetrics()
    {
        DataTable table = (DataTable)Session["Metrics"];
        int Desire = Convert.ToInt32(table.Rows[0]["Value"]);
        int Parti = Convert.ToInt32(table.Rows[1]["Value"]);
        int Advo = Convert.ToInt32(table.Rows[2]["Value"]);
        if (SNSIn.Checked)
        {
           table.Rows[0][1] = Desire +1;
           table.Rows[1][1] = Parti +1;
           table.AcceptChanges();
           Databind();
           Chart2.DataSource = table;
        }
        if (TTIn.Checked)
        {
            table.Rows[0][1] = Desire +1;
            table.Rows[2][1] = Advo +1;
            DataBind();
            Chart2.DataSource = table;

        }
        if (MusicIn.Checked)
        {
            table.Rows[0][1] = Desire +1;
            table.Rows[1][1] = Parti +1;
            DataBind();
            Chart2.DataSource = table ;

        }
    }

因此,例如,如果我选择 SNS,它将更新但不会应用新值,因此当我想选择音乐时,它不会向最新值添加一个

4

1 回答 1

0

You are missing few statements. This is what you need-

     if (TTIn.Checked)
        {
            table.Rows[0][1] = Desire +1;
            table.Rows[2][1] = Advo +1;
            table.AcceptChanges(); //missed
            Chart2.DataSource = table; //first datasource and then databind
            Chart2.DataBind();
        }
于 2012-12-12T12:01:04.727 回答