【问题标题】:How do I create a nice message when there are no rows in a Microsoft rdlc sub report?当 Microsoft rdlc 子报告中没有行时,如何创建漂亮的消息?
【发布时间】:2013-02-18 10:54:20
【问题描述】:

我在网站中使用 ReportViewer 控件,我的报告包含 3 个或更多子报告。子报告中的数据通常不存在,因为它是可选数据。我需要输出一个格式良好且对齐的消息,让读者知道。我有以下代码:

    protected void ReportViewer1_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        DataTable dtReport = GetReportSub(reportId);
        foreach (DataRow drRow in dtReport.Rows)
        {
            if (Replace(drRow["subName"].ToString(), " ", "") == e.ReportPath)
            {
                string sSQLMain = SQLReplacer(drRow["subSQL"].ToString());
                DataTable dtData = BuildCollectionArray(sSQLMain, new OdbcParameter());
                if (dtData.Rows.Count == 0)
                {
                    //TODO: Hide the report and show a friendly message
                }
                else
                {
                    ReportDataSource dataSource = new ReportDataSource("DS" + Replace(drRow["subName"].ToString(), " ", ""), dtData);
                    e.DataSources.Add(dataSource);
                }
                break;
            }
        }
    }

这将获取数据并将其添加到需要它的报告中。但是,如果没有数据,则唯一的选择是 NoRowsMessage 属性。但是,每个子报表的主报表中的 NoRowsMessage 属性限制太多。

理想情况下,我希望每个子报表都使用表达式或代码来处理 no rows 消息本身。但是,Microsoft 工作方式的缺陷似乎在于该报告以有数据显示为条件。

【问题讨论】:

    标签: report reporting reportviewer subreport report-viewer2010


    【解决方案1】:

    所以我找到了一个可行的解决方案来解决我的问题。我忽略了默认的无行功能,而是在子报告中进行工作。

    我有一个包含我的详细信息的 Tablix,然后我将创建一个额外的文本框,其中包含我的无行消息。根据 DataSet 隐藏 no rows 消息,例如:

    =iif(Sum(Fields!ActID.Value, "DSSub") > 0, true, false)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多