我想在按钮点击时从标签中减去数字。当我按下按钮时,点击值只减去一次,然后在第二次点击同一按钮时没有任何事情发生。我无法弄清楚问题是什么? - 这里是我的代码:
protected void btnTest_Click(object sender, EventArgs e)
{
Session["Counter"] = newValue;
if (ViewState["Markici"] != null)
{
dtCurrentTable = (DataTable)ViewState["Markici"];
ViewState["Markici"] = dtCurrentTable;
dtCurrentTable = (DataTable)ViewState["Markici"];
GridView2.DataSource = dtCurrentTable;
GridView2.DataBind();
var clickedRow = ((Button)sender).NamingContainer as GridViewRow;
var clickedIndex = clickedRow.RowIndex;
decimal old = dtCurrentTable.Rows[clickedIndex].Field<decimal>("Kolicina");
decimal oldIznos = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkIznos");
decimal VkDanok = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkDanok");
string Cena1 = dtCurrentTable.Rows[clickedIndex].Field<string>("Cena1");
int TarifaID = dtCurrentTable.Rows[clickedIndex].Field<Int32>("TarifaID");
decimal newIznos = oldIznos - Convert.ToDecimal(Cena1);
dtCurrentTable.Rows[clickedIndex].SetField("Kolicina", newValue.ToString());
dtCurrentTable.Rows[clickedIndex].SetField("VkIznos", newIznos.ToString());
//Here i do the operation
decimal minus = Convert.ToDecimal(Label42.Text) - Convert.ToDecimal(Cena1);
Label26.Text = minus.ToString();
}
答案 0 :(得分:0)
我一直在用错误的标签减去..
decimal minus = Convert.ToDecimal(Label42.Text) - Convert.ToDecimal(Cena1);
Label42.Text = minus.ToString();