![](/img/trans.png)
[英]Gridview sorting when Header text changed in RowDataBound event
[英]Gridview text changed event
我正在計算gridview價格字段值的總和,即gridview的textboxchanged事件中的textbox。 但是,當光標到達此行時: total +=Convert.ToDecimal(mytextbox);
獲取異常:輸入字符串的格式不正確。 這是我的gridviewtext更改的事件代碼:
protected void txtPrice_OnTextChanged(object sender, System.EventArgs e)
{
decimal total = 0.0m;
foreach (GridViewRow gvr in GrdTabRow.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow)
{
TextBox tb = gvr.FindControl("txtPrice") as TextBox;
string mytextbox = tb.ToString();
if (!mytextbox.Equals("") && mytextbox != null)
{
total +=Convert.ToDecimal(mytextbox);
}
}
GrdTabRow.FooterRow.Cells[2].Text = total.ToString();
}
}
嘗試:
string mytextbox = tb.Text.ToString();
total += Convert.ToDecimal(mytextbox);
ToString()我相信返回對象之間不同的對象表示,並不總是代表對象的特定值。 有時,它只是返回對象的全限定名。Text成員返回TextBox的值。 ToString()應該是可選的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.