将数量与价格和显示总数相乘

时间:2014-04-24 07:43:58

标签: c#

在gridview中我有一个编辑按钮,当我点击时,两个字段将更改为文本框数量和总数..当用户编辑数量时,必须自动计算总数并在总字段中显示结果..但是我在行

中收到错误
decimal price= Convert.ToDecimal(row.Cells[1].Text.Replace("$",  String.Empty).Replace(",", String.Empty));

输入字符串的格式不正确 这是代码

protected void txtQuantity_TextChanged(object sender, EventArgs e)
{
    TextBox txtQuantity = (TextBox)sender;
    GridViewRow row = (GridViewRow)txtQuantity.NamingContainer;
    TextBox txtTotal = (TextBox)row.FindControl("txtTotal");
    decimal price = Convert.ToDecimal(row.Cells[1].Text.Replace("$",  String.Empty).Replace(",", String.Empty));
    decimal total = price * Convert.ToInt32(txtQuantity.Text);

    txtTotal.Text = string.Format("{0:C}", total);
}

1 个答案:

答案 0 :(得分:0)

请改为尝试:

decimal price = decimal.Parse(row.Cells[1].Text.Replace("$", "").Replace(",", ""));
相关问题