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
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
DIVISION OF LABOR
Optional Category
Employee 1 [time worked]
Employee 2 [time worked]
Optional category totals
DIVISION OF LABOR TOTALS
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