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

NeedDataSource not fired for SubReport after converting to Q3 2012

1 Answer 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 04 Dec 2012, 03:51 PM
I just converted my Telerik reports to Q3 2012 and they all work except for two reports that have subreports.  The NeedDataSource event is not firing for the subreports.  Here is the code.  What am I doing wrong?  Thanks.
My report .aspx:
 
CPR_Reports.SalesActivityReport report1 = new CPR_Reports.SalesActivityReport(myConnectionstring, Convert.ToInt32(Session["pk"].ToString()), Convert.ToInt32(Session["cpruser_no"].ToString()), fromdate, todate);
InstanceReportSource instanceReportSource = new InstanceReportSource();
instanceReportSource.ReportDocument = report1;
this.ReportViewer1.ReportSource = instanceReportSource;
 
My report class:
 
public partial class SalesActivityReport : Telerik.Reporting.Report
{
    public SalesActivityReport(string myConnectionstring, int cfkwebuser, int cfkpnnames, string fromdate, string todate)
        {
            localConnectionstring = myConnectionstring;
            localCfkWebUser = cfkwebuser;
            localCfkPnnames = cfkpnnames;
            localFromDate = fromdate;
            localToDate = todate;
 
        InitializeComponent(reportHeaderBgColor, reportHeaderTextColor);
         
        SalesActivitySub1 salesActivitySub1 = new SalesActivitySub1();
            SubReport subReport1 = new Telerik.Reporting.SubReport();
            Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = salesActivitySub1;
            subReport1.ReportSource = instanceReportSource;
            subReport1.NeedDataSource += new EventHandler(subReport1_NeedDataSource);
 
    private void subReport1_NeedDataSource(object sender, EventArgs e)
        {
            EventLogger log1 = new EventLogger();
 
            string commandText = @"exec wa_SalesActivityCallsLogged2 " + localCfkPnnames + ",'" + localFromDate + "','" + localToDate + " 23:59:59'";
 
            try
            {
                SqlConnection sqlConnection1 = new SqlConnection();
                SqlCommand sqlSelectCommand1 = new SqlCommand();
                SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
                sqlConnection1.ConnectionString = localConnectionstring;
                sqlSelectCommand1.CommandText = commandText;
                sqlSelectCommand1.Connection = sqlConnection1;
                sqlDataAdapter1.SelectCommand = sqlSelectCommand1;
            this.DataSource = sqlDataAdapter1;
            }
            catch (Exception ex)
            {
                log1.WriteError(ex);
            }
            finally
            {
                log1.Dispose();
            }
        }
}

1 Answer, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 2
answered on 05 Dec 2012, 04:05 PM
And the solution, which I finally figured out, is:
My report class:
 
public partial class SalesActivityReport : Telerik.Reporting.Report
{
    public SalesActivityReport(string myConnectionstring, int cfkwebuser, int cfkpnnames, string fromdate, string todate)
        {
            localConnectionstring = myConnectionstring;
            localCfkWebUser = cfkwebuser;
            localCfkPnnames = cfkpnnames;
            localFromDate = fromdate;
            localToDate = todate;
 
        InitializeComponent(reportHeaderBgColor, reportHeaderTextColor);
 
        subReport1.Bindings.Add(new Telerik.Reporting.Binding("ReportSource", "= GetReportSource1('" + localConnectionstring + "','" + localCfkPnnames + "','" + localFromDate + "','" + localToDate + "','" + reportHeaderBgColor + "','" + reportHeaderTextColor + "')"));
    }
 
    public static ReportSource GetReportSource1(string localConnectionstring, string localCfkPnnames, string localFromDate, string localToDate, string reportHeaderBgColor, string reportHeaderTextColor)
        {
            var report = new SalesActivitySub1(reportHeaderBgColor, reportHeaderTextColor);
 
            EventLogger log1 = new EventLogger();
 
            string commandText = @"exec wa_SalesActivityCallsLogged2 " + localCfkPnnames + ",'" + localFromDate + "','" + localToDate + " 23:59:59'";
 
            try
            {
                SqlConnection sqlConnection1 = new SqlConnection();
                SqlCommand sqlSelectCommand1 = new SqlCommand();
                SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
                sqlConnection1.ConnectionString = localConnectionstring;
                sqlSelectCommand1.CommandText = commandText;
                sqlSelectCommand1.Connection = sqlConnection1;
                sqlDataAdapter1.SelectCommand = sqlSelectCommand1;
                report.DataSource = sqlDataAdapter1;
            }
            catch (Exception ex)
            {
                log1.WriteError(ex);
            }
            finally
            {
                log1.Dispose();
            }
 
            return new InstanceReportSource { ReportDocument = report };
        }
Tags
General Discussions
Asked by
Dan
Top achievements
Rank 2
Answers by
Dan
Top achievements
Rank 2
Share this question
or