Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DBNull的显示格式字符串未按预期工作_C#_Displayformat - Fatal编程技术网

C# DBNull的显示格式字符串未按预期工作

C# DBNull的显示格式字符串未按预期工作,c#,displayformat,C#,Displayformat,嗨,我已经为标签应用了显示格式字符串,如下所示 <dx:ASPxLabel ID="lblPrice" runat="server" Text='<%#Eval("Price")!=DBNull.Value? string.Format("{0:c}", Eval("Price")) :string.Format("{0:c}","0.00") %>' /> 这是在有数据时用$符号显示金额,但当0.00的值为空时,它不显示$符号。有人能帮我吗您需要将一些数字文字传递

嗨,我已经为标签应用了显示格式字符串,如下所示

<dx:ASPxLabel ID="lblPrice" runat="server" Text='<%#Eval("Price")!=DBNull.Value? string.Format("{0:c}", Eval("Price")) :string.Format("{0:c}","0.00") %>' />


这是在有数据时用
$
符号显示金额,但当
0.00的值为空时,它不显示
$
符号。有人能帮我吗您需要将一些数字文字传递到
格式
方法中,以便可以应用货币格式
{0:c}
,但是您正在传递字符串literal
“0.00”
。尝试将
“0.00”
文字更改为
0.0
0
0.00
,选择最可读的文字

而不是

string.Format("{0:c}", "0.00") //returns 0.00
您还可以将代码稍微简化为:

<%# string.Format("{0:c}", Eval("Price") != DBNull.Value ? Eval("Price") : 0 ) %>

<%# string.Format("{0:c}", Eval("Price") != DBNull.Value ? Eval("Price") : 0 ) %>