开发者

Gridview text changed event

开发者 https://www.devze.com 2023-01-28 11:48 出处:网络
I am calculating the total of gridview price 开发者_如何学Pythonfield values which is textbox in textboxchanged event of gridview. but while cursor is coming to this line: total +=Convert.ToDecimal(my

I am calculating the total of gridview price 开发者_如何学Pythonfield values which is textbox in textboxchanged event of gridview. but while cursor is coming to this line: total +=Convert.ToDecimal(mytextbox); getting the exception: Input string was not in a correct format. Here is my gridviewtext changed event code:

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();
    }  
}


try:

string mytextbox = tb.Text.ToString();
total += Convert.ToDecimal(mytextbox);

ToString() I believe returns the objects representation which differs between objects and doesn't always reprsent a specific value of an object. Sometimes it will simply return the full qualified name of the object.The Text member returns the value of the TextBox. The ToString() should be optional

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号