【问题标题】:Telerik - Can I load a report definition from DatabaseTelerik - 我可以从数据库加载报告定义吗
【发布时间】:2021-01-12 18:47:34
【问题描述】:

我正在开发一个 WebApplication,并在其中包含一个Telerik-Report。所描述的正常方式效果很好。

现在我正在尝试从数据库加载报告定义,而不是拥有一个文件(来自老板的请求)。到目前为止,我已经使它与一个临时文件一起工作,代码如下。但这远不是很好的编码。

我的问题:我能否以某种方式为报告提供字符串或流(而不是文件)?

我当前的代码如下所示:

private readonly string __path = "C:\\my-temp-directory\\Reports\\";
protected void Page_Load(object sender, EventArgs e) {
    string contents =  /** Get XML from Database **/;
    File.WriteAllText(__path + "temp.trdx", contents);   // <-- This file I want to omit.
    if (!IsPostBack) {
        this.reportViewer1.ReportSource.Identifier = "temp.trdx";
        this.reportViewer1.ReportSource.IdentifierType = IdentifierType.TypeReportSource;
    }
}

谢谢。

【问题讨论】:

    标签: c# telerik telerik-reporting


    【解决方案1】:

    好吧,报告定义只是一个 XML,所以从哪里获取它并不重要。查看代码我认为它不起作用,因为您有一个文件,但是在设置 IdentifierType 时使用的是 TypeReportSource 而不是 UriReportSource。

    在这种情况下,我认为您应该使用 CustomReportSource。 IdentifierType 可以是 TypeReportSource、UriReportSource 和 CustomReportSource。前两个不适用于您的情况,因为您不知道报告类型并且您也不想将其保存到文件中。 CustomReportSource 将允许您放置自己的逻辑,该逻辑将从数据库中获取报告并将其发送到引擎。实际上有一篇文档文章完全适合您的场景: How to Implement a Custom Report Source Resolver

    【讨论】:

    • 这确实是我最终做的。谢谢。
    猜你喜欢
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多