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

Table does not display report data source data

0 Answers 255 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 2
Dennis asked on 05 Apr 2012, 10:17 PM

I ran into the following issue when trying to build a report and although I finally found the answer in Telerik's documentation it wasn't without some lost productivity.  Perhaps this thread can help out some other developers.

Scenario:
So I was working on the visual representation on a number of .aspx web pages and
I had to switch over to create a report that was a form letter.  My typical process when I develop in this fashion is to...

  1. Develop the report without a data source
  2. Call the report programmatically and give it a data source
  3. Output the report to the web viewer, pdf or some other export format

In the form letter I wanted to create a date in a certain format and an inside address for the letter.  I created two user
functions to accomplish this. [Note:  If you haven't looked into using user functions for your Telerik reports then I would
recommend doing so as Telerik has provided a powerful mechanism for extending functionality].

In my Telerik Reporting Class Library, I added a class file named UserFunctions.vb  Here is the code:

Public Class UserFunctions
  
    Public Shared Function GetAddress(ByVal Name As Object, ByVal Addr1 As Object, ByVal Addr2 As Object, ByVal City As Object, ByVal State As Object, ByVal PostalCode As Object, ByVal Country As Object) As String
        Dim address As String = ""
        If Not IsDBNull(Name) AndAlso Name IsNot Nothing Then
            address &= Name.ToString.Trim & vbCr
        End If
        If Not IsDBNull(Addr1) AndAlso Addr1 IsNot Nothing Then
            address &= Addr1.ToString.Trim & vbCr
        End If
        If Not IsDBNull(Addr2) AndAlso Addr2 IsNot Nothing AndAlso Addr2.ToString.Trim.Length > 0 Then
            address &= Addr2.ToString.Trim & vbCr
        End If
        If Not IsDBNull(City) AndAlso City IsNot Nothing Then
            address &= City.ToString.Trim
        End If
        If Not IsDBNull(State) AndAlso State IsNot Nothing Then
            address &= ", " & State.ToString.Trim
        End If
        If Not IsDBNull(PostalCode) AndAlso PostalCode IsNot Nothing Then
            address &= "  " & PostalCode.ToString.Trim & vbCr
        End If
        If Not IsDBNull(Country) AndAlso Country IsNot Nothing AndAlso Country.ToString.Trim.Length > 0 Then
            address &= Country.ToString.Trim
        End If
        Return address
    End Function
  
    Public Shared Function GetLetterDate() As String
        Dim val As String = ""
  
        val = Now().ToString("MMMM d, yyyy")
  
        Return val
    End Function
  
End Class

The first function GetAddress takes several input parameters and builds an address.  The second function GetLetterDate() returns a date in the format (April 5, 2012).

This information I wanted to go into the Report Header section.  (Here is my mistake!!!)  Since I wanted the info of these 2 User Functions to show up side by side, I dropped a Table into the Report Header section of my Report.  I re-formatted the table to 1 row with 2 columns and entered the correct syntax for calling the user functions.  When I ran the report, my GetAddress function returned an empty string.  What was going on?

After wasting a decent amount of time, troubleshooting I finally figured out that the inputs to the GetAddress function were empty.  Why would the data source data be empty?  It wasn't when I passed it in.

Several days later (after solving the problem in a completely different way), I came across the following line in Telerik's documentation:

The Table report item is a separate data region and does not make use of the report's data source. It has its own Table..::.DataSource property which you have to set in order to populate the item with data.

And that was my whole problem!  I gave the Report a Data Source programmically.

Private Function ShowManagementLetterTest() As Telerik.Reporting.Report
    Dim showId As Integer = CInt(ID)
    Dim dtHdr As DataTable = csiShowDB.GetShowManagementLetter(showId)
    Dim report1 As New EmgLOSReports.TestReport1
    report1.DataSource = dtHdr
    Return report1
End Function

But I never gave the Table a Data Source (which can easily be accomplished with the following event code in the report itself)

Private Sub Table2_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles Table2.NeedDataSource
    If Table2.DataSource Is Nothing Then
        Table2.DataSource = Report.DataSource
        Dim dt As DataTable = CType(Report.DataSource, DataTable)
        TextBox10.Value = dt.Rows.Count.ToString
    End If
End Sub

Now, my whole problem started because I had carried over a style practice from web pages (using tables to line things up) to Telerik.Reporting (which does not need tables to align columns).

So, here were the learnings on my part...

  1. Make sure that your guidelines and practices apply to your environment  (I was in Telerik Reporting not web pages)
  2. Always keep in mind that there usually is a simpler way to solve your current dilemma (I didn't need tables to align items in Reporting)
  3. Telerik Reporting Tables require their own data sources!!!

I am attaching a PDF test report that shows the differences of using a Table with and without its' own data source.

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Dennis
Top achievements
Rank 2
Share this question
or