Reports empty unless one table is present

2 posts, 1 answers
  1. Czeshirecat
    Czeshirecat avatar
    66 posts
    Member since:
    Jun 2016

    Posted 30 Jan 2019 Link to this post

    I've a problem with a simple report which consists of upto 5 tables. Data comes from a single dataset containing 5 datatables.

    1) Unless one particular table contains data, then the detail section of that report is blank.

    My original design was a wrapper report with 5 sub reports. But when that showed the problem, I dropped the sub reports and generated the report as a flat file with 5 tables. This made no difference.

    I've tried rebuilding both the report and dataset several times. With the report I've used the wizard to add objectdatasource and the tablewizard to add the tables.

    2) One of the tests I've coded in there also shows that sometimes the "Order" column header isn't drawn. It consistently happens with that
    selection when it happens. I hope you can also look at this please.

    I've recreated a C# application that shows the problem, please see link. I hope you would run it in debug mode to see what's wrong. Just decompress the solution and run. Use the menu to select a test report. Print preview shows report header and footer and nothing else for those reports that fail.

  2. Answer
    Todor avatar
    520 posts

    Posted 04 Feb 2019 Link to this post

    Hi Czeshirecat,

    In SetPlanData method you assign Report DataSource (e.g. by 'DataSource = value;' line). The detail section of the Report is generated once for each item in the data source of the Report. In the case of DataSet, the first Table will be used as DataSource (i.e. dataset.Tables[0]) as there is *no* Table specified. Hence, when the first Table (dtFreeweight) is empty, the Detail section will *not* be generated and the report will be blank.
    I added the following code to the GenerateReportmethod to explore the issue :

    var countOfFirstTableRows = dataset.Tables[0].Rows.Count;
    var nameOfFirstTable= dataset.Tables[0].TableName;
    _report = new WorkoutPlanReport(memberName, planName);

    Note that nameOfFirstTable is dtFreeweight and the countOfFirstTableRows is 0 (zero) when the report is blank and non-zero otherwise.
    The specific Report does *not* need DataSource, hence you may just remove the code for setting it - this fixed the issue on our end.

     2. The TextBox lblStrengthOrder is passed as a parameter to SetDs method with each table, hence it gets its Visible value from the last SetDs call. You need to modify this argument accordingly for each table. Here is the code for SetPlanData that should fix both issues :

    private void SetPlanData(dsWorkoutPlanReport value)
        void SetDs(System.Data.DataTable source, Table destGrid,
          Telerik.Reporting.TextBox label, ObjectDataSource destDatasource)
            if (value.Tables[source.TableName].Rows.Count == 0)
                label.Visible = false;
                destGrid.Visible = false;
                destDatasource.DataSource = value.Tables[source.TableName];
        //DataSource = value;
        SetDs(value.dtStrength, tableStrength, lblStrengthOrder, odsStrength);
        SetDs(value.dtStretch, tableStretches, lblStretchOrder, odsStretch);
        SetDs(value.dtSwissBall, tableSwissball, lblSwissballOrder, odsSwissball);
        SetDs(value.dtFreeweight, tableFreeweights, lblFreeweightOrder, odsFreeWeight);
        SetDs(value.dtCv, tableCv, lblCvOrder, odsCv);

    Note that generally, we do not recommend modifying the report with code. We provide other means for dynamic report adjustment - check for example Bindings and Conditional Formatting.

    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top