开发者

Custom .ToString() Formats in .rdlc Reports

I have a custom business object which overloads the .ToString开发者_StackOverflow中文版() function. It also implements IFormattable.ToString, so I can define my own custom formats.

This approach seems to work everywhere in my app, except .rdlc reports. For example, I have a text field on a report with the following expression:

=Fields!MyField.Value.ToString("lr")

"lr" is a custom format I have created. When running the report I always get #Error as the output. I've placed breakpoints in my .ToString function and stepped through the code as the report is running, and I know the function is returning the correct value, but the report just doesn't seem to be capable of receiving and displaying it.


it is possible to do in a different way in the rdlc report you can use VB code. Just click on the report with right mouse button. When the context menu from where you enter parameters go to Proprties. When clicking it you should see a tab control witch few tab pages. Go to tab page "Code" an there right you VB function it must be something like this

 Public Function ParseVal(ByVal val As Object ) As String
     Dim MyClass As obj = CType(val, MyClass )
     return obj.ToString( "lr" ) 
    End Function

Then call the function in your textbox like this

= Code.ParseVal(Fields!MyField.Value )

P.S. I am not very sure if the VB code is working correctly just test it and if it is needed rewrite. If any other error occurs please post it to see what is the problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜