Telerik Forums
Reporting Forum
17 answers
1.0K+ views
I am writing this for 2 reasons.

Firstly to help out anyone that like me, has spent hours on Report Databinding issues.
Secondly, to put this down on paper (virtual?) to help me remember what I learned.
The problem I was having is related to binding a SQLDatasource to a report.
I was having a hell of a time trying to figure out why the filtered datasource was not getting reflected in the web report viewer.

Heres the setup I was using:

- A Telerik  Report with 1 table and 1 crosstab in a class library (as recommended by Telerik)
- The report had the report datasource, the table and crosstab datasources pointing to the reports SQLdatasource object.
-The report had no filters and no parameters and displayed all the data in the query (via stored proc) - good so far
-The report worked fine in the designer preview -also good
- A web page with a reportviewer
- Code behind setting the reportviewer report to the report described above (The working Code shown at the end of this article)

Now here is what was happening,

When I designed the report, and viewed it in the preview tab in the report designer, the report displayed fine and showed all the data in the query as it should.
When I viewed the report in the web page using the report viewer, I used code behind to get the data from a query, set a filter and bind the datasource of the report to that. The problem I was having was that the report was displaying all the data and not the filtered data.

I tried several things to troubleshoot this over several hours...
Some of the things I noticed were:
1. I could not get the NeedDatasource in the web report code behind to fire
2. If I put a Datagrid on the page bound to the same data, it showed the filtered data just fine but the report did not.
3. Weird- if I changed the filter to return no data (ID=9999), no data displayed in the report but if I used any valid filter (ID=1), all the data displayed
4. If I set the datasource in the report to nothing it displayed nothing even though getting set in code behind

After messing with this for several hours I got it to work properly and here's what I needed to do, and what I learned in the process:

The main problem I was having was that in my report, the main report was pointing to the report SQLdatasource, as were the 2 bound objects on the report, a table and a crosstab. All of the messing around I was doing was never setting the datasource of the 2 objects properly. Setting the main report datasource did not change the 2 bound objects in the report.

To fix this I did a few things:
1. Set the 2 objects datasources to point to the main report datasource using the NeedDataSource event (IN THE REPORT)
Private Sub Table1_NeedDataSource(sender As Object, e As System.EventArgs) Handles Table1.NeedDataSource
sender.DataSource = Report.DataSource
End Sub
  
Private Sub Crosstab1_NeedDataSource(sender As Object, e As System.EventArgs) Handles Crosstab1.NeedDataSource
sender.DataSource = Report.DataSource
End Sub

Something important to note here:
Dont use Table1.DataSource=Report.DataSource- it wont work. Make sure you refer to 'Sender'

2. In the report constructor, be sure to set the datasource to nothing (null in C#) or the NeedDataSources WILL NOT FIRE !

 

Public Sub New()
 InitializeComponent()
 Table1.DataSource =Nothing
  Crosstab1.DataSource =
Nothing
End Sub

So now in the report viewer (web page) code behind, when you run the method to load the report data, you set the main report datasource to the queried data object, whatever happens to be (Dataset, datareader, collection etc), and then since the report objects have their datasources set to nothing, the NeedDatasource events back on the report code behind fire and set the datasources for the table and crosstab to the main datasource for the report (which was set in the web page code behind).
Now- this gives us another very nice benefit, when you view the report in the report designer, it will work correctly because you leave the report and the table and the crosstab on the report bound to the SQL dataSource in the report. Some other forum posts I have seen recommended to set the datasource when building the report and then removing it when done designing.
You dont need to do that using this approach.

Here is the code for the report and web page code behind:

Report code behind (All the code)

Partial Public Class AI_Programs_Report_E
    Inherits Telerik.Reporting.Report
     
    Public Sub New()
        InitializeComponent()
        Table1.DataSource = Nothing
        Crosstab1.DataSource = Nothing
    End Sub
 
    Private Sub Table1_NeedDataSource(sender As Object, e As System.EventArgs) Handles Table1.NeedDataSource
        sender.DataSource = Report.DataSource
    End Sub
 
    Private Sub Crosstab1_NeedDataSource(sender As Object, e As System.EventArgs) Handles Crosstab1.NeedDataSource
        sender.DataSource = Report.DataSource
    End Sub
End Class
 
Web Page Code Behind (all revelant code only)

Imports Telerik.Web.UI
Imports Telerik.Reporting
=======================
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        SetReportDataSource()
Blah Blah...
=======================
    Protected Sub btnfilterNow_Click(sender As Object, e As System.EventArgs) Handles btnfilterNow.Click
        SetReportDataSource()
    End Sub
=======================
    Sub SetReportDataSource()
         Dim sql As String = DSListing.SelectCommand ' Select blah from blah
     Dim connectionString As String = "Data Source=(local);Initial Catalog=AI_DNN;Integrated Security=True"
Dim adapter As New SqlDataAdapter(sql, connectionString)
Dim dataSet1 As New DataSet()
adapter.Fill(dataSet1)
Dim table As DataTable = dataSet1.Tables(0)
Dim foundRows() As DataRow
Dim expression As String = "ID=563" ' Or some filter string
foundRows = table.Select(expression)
ReportViewer1.Report = New Report
Dim report1 As New TelerikReports_Sarvac.AI_Programs_Report_E()
report1.DataSource = Nothing ' DSListing ' dataSet
report1.DataSource = foundRows 'dataSet
ReportViewer1.Report = report1
ReportViewer1.RefreshReport()
end sub


I hope this clears some things up for you and saves you some time and headaches.
Please drop me an email if it does at billymac@advancedinteractive.net

Cheers...


Stef
Telerik team
 answered on 07 Mar 2013
3 answers
1.0K+ views
Hi,
  I am using report viewr for reports.Reports are working fine in my local,test and QA servers.But when we deployed in production server getting error "
An error has occurred while processing Report 'PrintReport': Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
"
Napa
Top achievements
Rank 1
 answered on 07 Mar 2013
4 answers
282 views
I have a report where I have a hierarchy of data related to work schedules.. Some of the time that is tracked has an additional grouping I need to total on, others don't.. see below:

DIVISION OF LABOR
   Optional Category
     Employee 1 [time worked]
     Employee 2 [time worked]
  Optional category totals
DIVISION OF LABOR TOTALS

Some divisions of labor will have the optional category that requires totals, some will not.
ADMIN STAFF
     Employee 1 [hours worked]
     Employee 2 [hours worked]
     Employee 3 [hours worked]
ADMIN STAFF TOTALS
 
SUPERVISION
   Supervisors
     Employee 1 [hours worked]
     Employee 2 [hours worked]
   Supervisors Totals
 
   Asst. Supervisors
     Employee 1 [hours worked]
     Employee 2 [hours worked]
   Asst. Supervisors Totals
 
SUPERVISION TOTALS
 
LABOR & LOGISTICS
   Labor Foreman
     Employee 1 [hours worked]
     Employee 2 [hours worked]
   Labor Foreman Totals
 
   Laborer / Logistics
     Employee 1 [hours worked]
     Employee 2 [hours worked]
   Laborer / Logistics Totals
 
   Laborer
     Employee 1 [hours worked]
     Employee 2 [hours worked]
   Laborer Totals
 
LABOR & LOGISTICS TOTALS

In the above, Admin Staff has no sub-category or totals. Labor & Logistics does. 

So.. I need a grouping with totals for the "Optional" category but do not need that optional category for Admin staff and other divisions of labor that do not need sub-grouping categories. I have the data being captured already, I just need to know how make the report do this.

Thanks.
Matthew
Top achievements
Rank 1
 answered on 07 Mar 2013
1 answer
199 views
Hi there.

I have a crosstab report. The headers are split by company region then by year. How do I split my grand total column by year, i.e. the second type of header?

Thanks
Hadib Ahmabi
Top achievements
Rank 1
 answered on 07 Mar 2013
5 answers
736 views
Hi,

I can't get the table row group headers in a report I'm designing to repeat on every page. Here's the table group structure I have

ParentGroup
Static
Static
Detail Group

I would like the two static rows to be repeated when a group spans multiple pages. I'm using Q1 2013.

Thanks,

Joe
Elian
Telerik team
 answered on 07 Mar 2013
1 answer
171 views
Hello, I'm the trail user. currently I'm experiencing some difficulty on report in visual studio, the select box is empty while creating a new report. I tried to add new data source through report property but the select box is still empty.

Add folder in VS project --> add new item --> telerik report -->(report wizzard poped up) --->new report --> next -->add new data source --> the select window is empty (should show some select option like sqldata client something) datasource name is disabled) --> cancel to exit wizzard

then add a binding datasource control to project ---> VS crashes.

tried to delete report and reinstall, still have same problem
IvanY
Telerik team
 answered on 07 Mar 2013
5 answers
169 views
Earlier today I successfully installed a trial versio of RAD Controls for ASP.NET AJAX. I then attempted to install a trial version of Telerik Reporting. I am installing on Windows Server 2008R2, and am using Visual Studio 2010.
The installation process appears to run successfully for a while, and then msbuild.exe starts and a 'Windows Installation Coordinator' window opens up and the process runs forever.
I cancel the process, cancel the installation, unsinstall and try again. Same result.
The attached document (in a zip file) shows what the screen looks like. Do you have any ideas? Thanks.
Bill S.
Blas
Top achievements
Rank 2
 answered on 06 Mar 2013
5 answers
106 views
Hi I am just testing out the ASP.net Reportviewer on IE10 (in SharePoint 2013). The report never completes (we can see the spinning animation for ever). Is this supported ? 

Our version of the reports is 6.2.12.1017
Petio Petkov
Telerik team
 answered on 06 Mar 2013
1 answer
117 views
Hi everyone
I'd like to  know, if its possible to create telerik reports , using the N-tier(3tier)way.
If it's possible , can you please (if possible) release a video, or basic walk-through tutorial, on how its done.
Tx
Hadib Ahmabi
Top achievements
Rank 1
 answered on 06 Mar 2013
1 answer
1.1K+ views
Hello,
I am getting this error when running an application that loads my class library which presents a reportviewer in a windows form

"System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type."

My class library is built using Visual Studio 2010 and C#, targetting .Net Framework 4 and Platform is set to AnyCPU. I have tried with both Q3 2012 and Q1 2013 versions of Telerik Reporting but I get the same error.

I have also installed on the same machine Visual Studio 2012 and the .Net Framework version seems to be 4.5 (System.DLL version is 4.0.30319.18034).

Can you suggest how I may overcome this please?
Thanks
Craig
Craig
Top achievements
Rank 1
 answered on 06 Mar 2013
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?