按日期排序,Telerik Reports 中可能为空
报告中有一个列,其中有一个格式为 MM/dd/yyyy 的字符串日期字段。其中一些列可能包含空字符串。对某个部分进行排序时遇到问题。我大约花了 10 个小时才开始 Telerik 报道,所以我可能会遗漏一些明显的东西。
我最初尝试使用这样的表达:
=IIf(Fields.ExpirationDate='', CDate('1/1/1990'), CDate(Fields.ExpirationDate))
这看起来正确吗?这引发了一个错误: 处理报告“”时发生错误: 无法比较数组中的两个元素。
------------- InnerException ------------- 执行函数 CDate() 时发生错误。 进一步检查 InnerException 信息。 ------------- InnerException ------------- 调用目标已引发异常。 ------------- InnerException ------------- 字符串未被识别为有效的日期时间。
另一位开发人员建议使用自定义方法,因此我在 report.cs 文件内创建
public DateTime EmptyDateToNow( string expirationDate )
{
DateTime parsed;
if (!DateTime.TryParse(expirationDate, out parsed))
return DateTime.Now;
return parsed;
}
,然后尝试使用 =EmptyDateToNow(Fields.ExpirationDate) 进行调用
,这会引发错误:
处理时发生错误 报告“”:无法比较两个 数组中的元素。 ------------- InnerException ------------- 表达式包含未定义的函数调用 EmptyDateToNow()。
Have a column in a report which a string date field in the format of MM/dd/yyyy. Some of those columns may contain empty strings. Having a problem sorting a section. I am about 10 hours in to telerik reporting so I may be missing something obvious.
I initially tried to use a expression like this:
=IIf(Fields.ExpirationDate='', CDate('1/1/1990'), CDate(Fields.ExpirationDate))
Does that look correct? This threw an error:
An error has occured while processing Report '':
Failed to compare two elements in the array.
------------- InnerException ------------- An error has occured while executing function CDate().
Check InnerException for further
information.
------------- InnerException ------------- Exception has been thrown by the target of an invocation.
------------- InnerException ------------- String was not recognized as a valid DateTime.
Another developer suggested using a custom method so I created inside the report.cs file
public DateTime EmptyDateToNow( string expirationDate )
{
DateTime parsed;
if (!DateTime.TryParse(expirationDate, out parsed))
return DateTime.Now;
return parsed;
}
and then tried to call with =EmptyDateToNow(Fields.ExpirationDate)
and this throws the error:
An error has occured while processing
Report '': Failed to compare two
elements in the array.
------------- InnerException ------------- The expression contains undefined function call
EmptyDateToNow().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
public static DateTime EmptyDateToNow( stringexpirationDate )
我认为 Telerik Reporting 希望您的用户函数是静态方法。
我认为第一种方法的问题在于,即使表达式为 true,CDate(Fields.ExpirationDate) 也会被执行,从而导致抛出异常。您可以尝试这样的方法来获得所需的结果,而不需要定义用户函数:
我意识到这有点旧,我只是想发布以防其他人遇到麻烦并搜索它。
public static DateTime EmptyDateToNow( string expirationDate )
I think that Telerik Reporting wants your user functions to be static methods.
I am thinking that the problem with the first approach is that CDate(Fields.ExpirationDate) is being executed even if the expression is true thereby causing the exception to be thrown. You might try something like this to get the desired result without defining a user function:
I realize this is a bit old, I just wanted to post in case anyone else is having troubles and searching this.
使用户函数静态(如果调用仍然失败,则使调用完全限定。例如 =Myclass.EmptyDateToNow(Fields.ExpirationDate))。
使函数接收一个对象作为参数(不是字符串或任何其他数据类型)。
在函数内部,检查是否为 null,然后(不是 null)转换为正确的数据类型并使用它。
Make the user function static (and if the call still fails, make the call fully qualified. e.g. =Myclass.EmptyDateToNow(Fields.ExpirationDate)).
Make the function receive an object as a parameter (not a string or any other data type).
Inside the function, check for null and then (it not null) convert to the proper data type and work with it.