lkosson / reportviewercore

Recompilation of Microsoft.ReportViewer for .NET Core 3.1+
427 stars 123 forks source link

How do I set the number of pages automatically based on the number of rows? #151

Closed ctechid closed 1 year ago

ctechid commented 1 year ago

I print a table containing 10 rows, but why do 4 pages appear there? Page 1 is correct, but Page 2, Page 3, Page 4 are empty (I marked the red box).

How do I set the number of pages automatically based on the number of rows?

Thanks, Erwin

        public static void SetContent(String company, String title, String subTitle, List<BalanceLogModel> balanceLogList, LocalReport report)
        {
            try
            {
                var titleParam = new ReportParameter("TitleParam", title);
                var subTitleParam = new ReportParameter("SubTitleParam", subTitle);
                var companyParam = new ReportParameter("CompanyParam", company);
                var parameters = new[] { titleParam, subTitleParam, companyParam };

                // create table
                var dt = new DataTable("BalanceLogDataTable");

                // create columns
                var dcID = new DataColumn("ID");
                dcID.DataType = typeof(Int32);

                var dcDatetime = new DataColumn("datetime");
                dcDatetime.DataType = typeof(String);

                var dcCardNumber = new DataColumn("card_number");
                dcCardNumber.DataType = typeof(String);

                var dcCustomerID = new DataColumn("customer_id");
                dcCustomerID.DataType = typeof(String);

                var dcCustomerName = new DataColumn("customer_name");
                dcCustomerName.DataType = typeof(String);

                var dcBalance = new DataColumn("balance");
                dcBalance.DataType = typeof(Int32);

                // add columns to table
                dt.Columns.AddRange(new DataColumn[] { dcID, dcDatetime, dcCardNumber, dcCustomerID, dcCustomerName, dcBalance });

                // fill rows
                foreach (var item in balanceLogList)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    var row = dt.NewRow();
                    row["ID"] = item.BalanceLogID;
                    row["datetime"] = item.BalanceLogDatetime;
                    row["card_number"] = item.BalanceLogCardNumber;
                    row["customer_id"] = item.BalanceLogCustomerId;
                    row["customer_name"] = item.BalanceLogCustomerName;
                    row["balance"] = item.BalanceLogBalance;
                    dt.Rows.Add(row);
                }

                // create dataset
                var ds = new DataSet("BalanceLogDataSet");

                // add table to dataseet
                ds.Tables.Add(dt);

                // set datasource
                var datasource = new ReportDataSource("BalanceLogDataSet", dt);

                // rdlc stream
                using var rdlcStream = new FileStream(Settings.Default.BalanceLogReportFile, FileMode.Open);
                report.LoadReportDefinition(rdlcStream);
                report.DataSources.Clear();
                report.DataSources.Add(datasource);
                report.SetParameters(parameters);
                report.Refresh();
            }
            catch (Exception ex)
            {
                ExLogger.LogException(ex, "");
            }
        }

image

image

image

crazycga commented 1 year ago

I can help here.

Your issue is that the report is going over the edge of the right side of the page. Right click outside the report, go to report properties. Your page size setting needs to be made here. Then also check to ensure that your data matrix isn't exceeding that size.

This is an SSRS report issue, not a module issue. I almost guarantee it.

ctechid commented 1 year ago

I can help here.

Your issue is that the report is going over the edge of the right side of the page. Right click outside the report, go to report properties. Your page size setting needs to be made here. Then also check to ensure that your data matrix isn't exceeding that size.

This is an SSRS report issue, not a module issue. I almost guarantee it.

Thank you, changing the width and height of the Report made the number of pages as expected.

image

Result:

image

Best Regards,