This is a migrated thread and some comments may be shown as answers.

Multivalue parm: displaymember values as report content

1 Answer 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Raoul
Top achievements
Rank 1
Raoul asked on 30 Apr 2012, 09:56 PM
I would like to add te selected values of a multivalued parm to the header of my report. E.g. I have a drop down with doctors loaded with a sql data source where doctorid (Guid) is the value member, and name (string) the display member. In my report I want to show the selected doctors or all available in case of no selection. I do not want to show the guids (obviously) but the names...
Yet, only the value members are accessible,  where I would like the get my hands on the display members.

This is my (working) code:
Public Shared Function VoorschrijverLabels(ByVal selection As Object(), ByVal reportItem As Object) As String
 
        Dim labels As String = String.Empty
 
        Try
             Dim processingReport As Telerik.Reporting.Processing.Report = TryCast(reportItem, Telerik.Reporting.Processing.ReportItemBase).Report
             Dim report As rptDagstaat = TryCast(processingReport.ItemDefinition, rptDagstaat)
            Dim da As New SqlDataAdapter(report.dsVoorschrijvers.SelectCommand, report.dsVoorschrijvers.ConnectionString)
            Dim ds As New DataSet
            da.Fill(ds)
 
            For Each row As DataRow In ds.Tables(0).Rows
                If labels.Length > 0 Then labels += "; "
                If selection Is Nothing OrElse selection.Contains(row("VoorschrijverID").ToString) Then
                    labels += row("Voorschrijver")
                End If
            Next
 
        Catch ex As Exception
        End Try
 
        Return labels
 
    End Function
Basically I do an extra query to the database to get the paramater datasource values (again!), and compare them against the selected  value members.
But as you can see, it is not very generic... It's per parameter because I need to cast the report to access the parameter data source and the specific parameter data source properties. A separate function for each multivalued parameter with a separate database call...

The selection variable contains an ArrayList(Of string) These are casted value members of the parameter data source {CStr(VoorschrijverID)} The result of this function is a string with the names of the doctors semicolon separated.

My question is: Is there a more easy way to do this? Preferably without the database call and accessing the parameter data source directly.

Regards,
Raoul

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 03 May 2012, 04:51 PM
Hi Raoul,

You can directly access the selected report parameter display member with the following expression:
=Parameters.ReportYear.Label
However if you utilize multi value report parameter you will have to format the resulting string array in the required string format. For this you can use an user function as shown in the following example:

Public Shared Function FormatArray(ByVal array As IList) As String
    Dim sb As New StringBuilder()
 
    For Each o As Object In array
        If sb.Length > 0 Then
            sb.Append("; ")
        End If
        sb.Append(o.ToString())
    Next
 
    Return sb.ToString()
End Function

Greetings,
Peter
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Tags
General Discussions
Asked by
Raoul
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or