Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
If Me.IsPostBack Then |
If Me.RadDatePickerStartDate.SelectedDate.HasValue = True And Me.RadDatePickerEndDate.SelectedDate.HasValue = True Then |
Dim newrpt As New rptSummary(CDate(Me.RadDatePickerStartDate.SelectedDate.Value), CDate(Me.RadDatePickerEndDate.SelectedDate.Value)) |
Me.ReportViewer1.Report = newrpt |
Response.Write( CType(CType(Me.ReportViewer1.Report, rptSummary).DataSource, svcDailyStats.clsDailyStatistics).intTotalCalls)
|
End If |
End If |
End Sub |
And here we see some code from my report
Imports System.ComponentModel |
Imports System.Drawing |
Imports System.Windows.Forms |
Imports Telerik.Reporting |
Imports Telerik.Reporting.Drawing |
Partial Public Class rptSummary |
Inherits Telerik.Reporting.Report |
Private objDailyStats As svcDailyStats.DailyStats |
Private DailyStats As svcDailyStats.clsDailyStatistics |
Public Sub New() |
InitializeComponent() |
objDailyStats = New svcDailyStats.DailyStats |
DailyStats = objDailyStats.GetDailyStatsEmpty() |
Me.DataSource = DailyStats |
End Sub |
Public Sub New(ByVal startDate As Date, ByVal enddate As Date) |
InitializeComponent() |
objDailyStats = New svcDailyStats.DailyStats |
DailyStats = objDailyStats.GetDailyStats(startDate, enddate) |
Me.DataSource = DailyStats |
End Sub |
End Class |
Now as an example lets assume I submit my page with the values of RadDatePickerStartDate = '01/03/2009' and RadDatePickerEndDate = '02/03/2009'
The report runs, the datasource is set with the newly created business object using these 2 dates as expected.
Now lets suppose I change those 2 dates and submit the page again, for some reason the report doesn't change. You'll see the response.write in the above code, intTotalCalls is a property of my business object that I am setting as a datasource for my report. This value will change and display on my page as expected for the response.write but it will not change in my visible report and always remains the same as the first time the report was run as do all other fields in the report.
private void detail_ItemDataBound(object sender, EventArgs e)
{
Telerik.Reporting.Processing.DetailSection section = sender as Telerik.Reporting.Processing.DetailSection;
DataRowView row = section.DataItem as DataRowView;
object ID = row.Row["ID"];
if ((row["ID"] != null) && (row["ID"].ToString().Length != 0))
{
//pass parameter- ID, date from & date to
this.subDrivingLicense.ReportSource = new rptDriverReminderSub1();
this.subDrivingLicense.ReportSource.DataSource = blDrivingLicense.ListRecords(ID.ToInt(), strDateFrom, strDateTo);
}
}
but sub report always show "the expression contains object "ExpiryDate" that is not defined in the current context".
What should i do to fix it?anything i miss out?
Private Sub SubReport1_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) _ |
Handles MyBase.NeedDataSource |
'Take the Telerik.Reporting.Processing.Report instance |
Dim report As Telerik.Reporting.Processing.Report = CType(sender, Telerik.Reporting.Processing.Report) |
' Read connection string from app.config / web.config |
Dim connSettings As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("SiteSqlServer") |
If (connSettings IsNot Nothing) AndAlso (connSettings.ConnectionString <> Nothing) Then |
Me.SubReport1DataSetTableAdapter1.Connection.ConnectionString = connSettings.ConnectionString |
'ReportParameter value to SQL |
Dim param As Integer = report.Parameters("Parameter") |
Me.SubReport1DataSetTableAdapter1.Fill(Me.SubReport1DataSet.SubReport1DataSetTable, param) |
' Set report data source |
report.DataSource = Me.SubReport1DataSetTableAdapter1 |
End If |
End Sub |
Private Sub SubReport1_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) _ |
Handles MyBase.NeedDataSource |
'Take the Telerik.Reporting.Processing.Report instance |
Dim report As Telerik.Reporting.Processing.Report = CType(sender, Telerik.Reporting.Processing.Report) |
' Read connection string from app.config / web.config |
Dim connSettings As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("SiteSqlServer") |
If (connSettings IsNot Nothing) AndAlso (connSettings.ConnectionString <> Nothing) Then |
Dim conn As SqlConnection = New SqlConnection(connSettings.ConnectionString) |
Dim commandText As String = "SELECT ... WHERE id = @Parameter" |
Dim cmd As New SqlCommand(commandText, conn) |
'ReportParameter value to SQL |
Dim param As Integer = report.Parameters("Parameter") |
cmd.Parameters.Add("@Parameter", SqlDbType.VarChar, 10).Value = param |
Dim adapter As New SqlDataAdapter(cmd) |
Dim ds As New DataSet() |
adapter.Fill(ds) |
report.DataSource = adapter |
End If |
End Sub |