Tag Archives: SSRS

SSRS Custom Code to Get Textbox Name

Here’s a simple SSRS function that will get you the textbox name.

Public Function TextBoxName(ByVal meString As String) As String
Dim s As Integer = 19
Dim e As Integer = meString.IndexOf(“_TextBoxExprHost”) – 19
TextBoxName = meString.Substring(s,e)
End Function

Expression:
=Code.TextBoxName(Me.ToString)

‘Me’ is the object you are ‘in’… and Me.ToString returns the following:

“ReportExprHostImpl+[TextBoxName]_TextBoxExprHost+Paragraph00_ParagraphExprHost+TextRun00_TextRunExprHost”

Our custom code extracts the Textbox Name from the Me string.

————————————————————–



Report > Report Properties > Code

1

Add the expression where you need it… i.e. maybe you need to dynamically change the background color of all textboxes in a table, or set the hidden property.

2

Here’s the output:

3

SSRS Bullet List from an Array of Values

Thought I’d give this blogging thing a try; so here’s my first attempt at blogging a recent challenge I had in getting Reporting Services to display a bullet list from an array of values.

To get right down to it; say you wanted to convert the following list of skills into a bullet list:
Capture
||
||
/
Capture2
Navigate to Report Properties > Code and copy the following code into the Custom Code box. If you need to customize it even further; I have no objection.
Capture3

Public Shared Function SetBullet(ByVal Value As String, ByVal Delimiter As String) As String
””””””””””””””””””””””””””””””””’
‘ Declare and load array with Split FN using Delimiter parameter
””””””””””””””””””””””””””””””””’
Dim ListArray() As String
ListArray = Split(Value, Delimiter)
””””””””””””””””””””””””””””””””’
‘ Remove any ’empty’ values from array
””””””””””””””””””””””””””””””””’
Dim LastNonEmpty As Integer = -1
For i As Integer = 0 To ListArray.Length – 1
If ListArray(i) <> “” Then
LastNonEmpty += 1
ListArray(LastNonEmpty) = ListArray(i)
End If
Next
ReDim Preserve ListArray(LastNonEmpty)
””””””””””””””””””””””””””””””””’
‘ Apply bullet html markup to the list array
””””””””””””””””””””””””””””””””’
Dim RetValue As String = “”
Dim x As String = “”
RetValue = “<ul>”
For Each x In ListArray
RetValue = RetValue + “<li>” + x + “</li>”
Next
RetValue = RetValue + “</ul>”
Return RetValue
End Function

Back in the report, modify the expression for the field you want to apply bullets to and wrap the field with the following code:

=Code.SetBullet(Fields!Skills.Value, “~”)

Capture4

The first parameter in the SetBullet function is the field (or custom hard coded values) to which you want to apply the bullet style.The second parameter is the delimiter used in your list of values.

The code will handle any ’empty’ entries and remove them from the list in case you have one too many delimiters applied side-by-side or at the end of your list.

Once you’ve applied the function to your field, you need to change the markup type to convert the contents to HTML.

Click inside the item to highlight your new expression. Once highlighted, right-click > Placeholder Properties.

Capture5
Select the markup type to be ‘HTML – Interpret HTML tags as styles’. This is pretty much self explanatory.
Capture6
…and voila! You got yourself a bullet list from an array of values.
Capture2

Reporting Services doesn’t support a wide range of HTML code, but here are some documented features (per Microsoft):

The following is a complete list of tags that will render as HTML when defined as placeholder text:
  • Hyperlinks: <A href>
  • Fonts: <FONT>
  • Header, style and block elements: <H{n}>, <DIV>, <SPAN>,<P>, <DIV>, <LI>, <HN>
  • Text format: <B>, <I>, <U>, <S>
  • List handling: <OL>, <UL>, <LI>
Be careful with adding CSS attributes, as some may not work on all tags.
Here’s what Microsoft has to say about it.