十进制到字符串转换 [英] Decimal to String Conversion

查看:120
本文介绍了十进制到字符串转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标签lblTotal =(标签)e.Row.FindControl(lbltotal);

total = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem,AchievedPer));

string stotal = Convert.ToDecimal(total).ToString();

lblTotal.Text = stotal.ToString(); //< ---出现错误这个声明





如何以最佳方式输入演员?

解决方案

< blockquote>试试这个.. :)



标签lblTotal =(标签)e.Row.FindControl(  lbltotal); 
total = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, AchievedPer));
decimal stotal = Convert.ToDecimal(total);
lblTotal.Text = Convert.ToString(stotal);


简单:它在行中找不到名为lbltotal的控件,因此返回 null value。

当您尝试设置null值的Text属性时,它会抛出需要对象引用异常。



所以看看你的行,找出它为什么没有lbltotal。有很多可能的原因,但我们看不到你的代码,所以我们无法告诉你。

首先使用调试器并在行后立即查看e.Row :

标签lblTotal =(标签)e.Row.FindControl(  lbltotal); 

您需要知道它包含的内容,以便您可以查看它包含的内容!


Label lblTotal=(Label)e.Row.FindControl("lbltotal");
total = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "AchievedPer"));
string stotal = Convert.ToDecimal(total).ToString() ;
lblTotal.Text =stotal.ToString();//<---Error occurs in this statement


How to type cast in the best way?

解决方案

try this.. :)

Label lblTotal = (Label)e.Row.FindControl("lbltotal");
total = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "AchievedPer"));
decimal stotal = Convert.ToDecimal(total);
lblTotal.Text = Convert.ToString(stotal);


Simple: it can't find a control called "lbltotal" in the row, so it returns a null value.
When you try to set the Text property of a null value it throws a "Object reference is required" exception.

So look at your row, and work out why it doesn't have "lbltotal". There are so many possible reasons why, but we can't see your code, so we can't tell you.
Start by using the debugger and looking at e.Row in detail immediately after the line:

Label lblTotal=(Label)e.Row.FindControl("lbltotal");

You need to know what it does contain, so you can look at what you thought it contained!


这篇关于十进制到字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆