Wednesday, April 6, 2016

Insert Custom Function in ReportViewer

Step by step to insert custom function in report viewer.
Normally, if you want to put some logic to display the data in ReportViewer, you just put your code in the expression box. However, putting long and complex code in the expression box almost make the code unreadable.

This tutorial will provide you on how to create custom function separate your code and shorten the code in expression box.

1Click on empty area of your report viewer

2On the properties pane, double click "code", then you can add custom function in VB script

For example
Dim private rowCount as integer = 0

Public function RowNumberOfGroup(Byval resetRowNumber as Boolean) as integer

  if resetRowNumber Then
    rowCount = 0
  End if
  
  rowCount = rowCount + 1
  Return rowCount
End function

3Then in expression box, you can call your custom function with this syntax:
Code.<your custom function in step 2>(parameters ... )



Happy Coding!

No comments:

Post a Comment