在 RDLC 报告中格式化空时间 [英] Formatting null time in RDLC report

查看:55
本文介绍了在 RDLC 报告中格式化空时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将记录集中的时间值带回到 RDLC 报告中.(c# Visual Studio 2013)
他们即将到来的是一个可为空的时间跨度.
我显示为 HH:MM

I am bringing back time values from a record set into an RDLC report. (c# Visual Studio 2013)
They are coming is as a nullable Timespan.
Which i display as HH:MM

这一切看起来都很好,直到我得到一个空值,如果没有时间记录,则返回空值,因为它是可空的时间跨度类型.发生这种情况时,我会在 RDLC 报告中收到 #error.我想要发生的是要么显示 "00:00" ,要么只是空白.

This all looks fine until i get a null , if there is no time for record a null is returned,as it's a nullable timespan type. When this happens i get an #error in the RDLC report. What i want to happen is either show "00:00" , or just blank.

我已尝试向 RDLC 中的 Expression 字段添加一个 IFF,以便如果返回 null,我将不显示任何内容或 "00:00" ,但两者都返回相同的结果,即字段中的 #error.

I have tried adding an IFF to the Expression field in RDLC so that if a null is returned i show nothing , or "00:00" , but both return the same result , a #error in the field.

=IIF(IsNothing(Fields!Hours.Value),nothing,Format(TimeValue(Fields!Hours.Value.ToString),"hh:mm"))

有什么想法吗?谢谢.

解决方案更新:

感谢您的帮助:这是我用来在我的情况下使其工作的最终表达式:

Thanks for all your help : This is the final expression i used to get this working in my case:

=IIF(Fields!Hours.Value.ToString = "00:00:00","",Format(TimeValue(Fields!Hours.Value.ToString),"hh:mm"))

推荐答案

尝试用空字符串替换 nothing 值.也用 X is nothing 代替 ISNOTHING(x):

Try replacing the nothing value with an empty string. Also use X is nothing instead of ISNOTHING(x):

=IIF(Fields!Hours.Value is nothing,"",Format(TimeValue(Fields!Hours.Value.ToString),"hh:mm"))

无论您尝试什么,您都会得到 #error 的事实让我怀疑该表达式是否完全正确,或者您是否还有其他功能,例如自动格式化或类似的东西.

The fact that you get #error no matter what you tried makes me wonder whether the expression is correct at all or if you have something going on in addition, like automatic formatting or stuff like that.

请尝试在前景色上使用此表达式并将颜色设置为 Red 以防值为 nullGreen 以防它不是.还要检查是否选择了一些可能导致错误的显示格式.

Please try to use this expression on the foreground color and set the color to Red in case the value is null and Green in case it is not. Also check whether there's some display format selected that could cause errors.

这篇关于在 RDLC 报告中格式化空时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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