将decimal转换为string时出错

将decimal转换为string时出错

本文介绍了将decimal转换为string时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

decimal a = 0;
             for (Int32 i = 0 ; i< this.GridView1.Rows.Count; i++)
             {

                 a = a+ Convert.ToDecimal(((Label)GridView1.Rows[i].FindControl("lbl_price")).Text.ToString());

             }
             lbl_total.Text =  Convert.ToString(a);



这是我的代码,在最后一行当我我将a的值分配给标签m得到错误?

错误是这个...


this is my code and in the last line when i am assign the value of a into label m getting error?
error is this...

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 104:                
Line 105:             }
Line 106:             lbl_total.Text =  Convert.ToString(a);
Line 107:         
Line 108:        }

推荐答案


decimal a = 0;
           for (Int32 i = 0; i < this.GridView1.Rows.Count; i++)
           {

               a = a + Convert.ToDecimal(((Label)GridView1.Rows[i].FindControl("label3")).Text.ToString());

           }
           lbl_total.Text = Convert.ToString(a);


这篇关于将decimal转换为string时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 19:00