Telerik 报告 |通过查询字符串设置报告参数

发布于 2024-12-06 06:23:12 字数 919 浏览 0 评论 0原文

问题: 我试图将页面上的查询字符串中的报表参数值传递到已定义参数的报表。我似乎无法将值一路传递到报告中。

        Telerik.Reporting.Report report = new MyCustomReportLibrary.TelerikReport();
        report.ReportParameters["parameterName"].Value = Request.QueryString["Id"];

        ReportViewer.Report = report;

上面的语法很好,但是当变量 "report"TelerikReport() 构造函数创建时,它还没有参数值,当我设置它时事后看来这并不重要。即使我尝试调用 ReportViewer.RefreshReport()

我看过的地方:

感谢您的帮助,

克里斯

Problem:
I am trying to pass a Report Parameter value from the query string on the page to my report that already has the parameter defined. I just can't seem to get the value passed all the way to the report.

        Telerik.Reporting.Report report = new MyCustomReportLibrary.TelerikReport();
        report.ReportParameters["parameterName"].Value = Request.QueryString["Id"];

        ReportViewer.Report = report;

This syntax above is fine but when the variable "report" is created by the TelerikReport() constructor it doesn't have a value for the parameter yet and when I set it after the fact it doesn't seem to matter. Even if I try to call a ReportViewer.RefreshReport().

Places I have looked:

Thanks for the help,

Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情愿 2024-12-13 06:23:12

我可以通过更改 MyCustomReportLibrary.TelerikReport 的构造函数来使其工作。希望这可以帮助任何寻找答案的人。

很像这个例子
Telerik 论坛 |将报告参数从 Rad 窗口传递到 Telerik 报告

Telerik 报告代码 (TelerikReport.cs)

    public TelerikReport(int Id)
    {
        //
        // Required for telerik Reporting designer support
        //
        InitializeComponent();

        this.ReportParameters["parameterName"].Value = Id;
    } 

ASP.Net 页面代码 (ReportViewerPage.cs)

    protected void Page_Load(object sender, EventArgs e)
    {
        Report raReport = new TelerikReport(Request.QueryString["Id"] as int);
        ReportViewer1.Report = raReport;
    }

I was able to get it to work by altering the Contructor for MyCustomReportLibrary.TelerikReport. Hope this helps anyone looking for the answer.

Much like this example
Telerik Forums | Pass Report parameters from Rad window to a telerik report

Telerik Report Code (TelerikReport.cs)

    public TelerikReport(int Id)
    {
        //
        // Required for telerik Reporting designer support
        //
        InitializeComponent();

        this.ReportParameters["parameterName"].Value = Id;
    } 

ASP.Net Page Code (ReportViewerPage.cs)

    protected void Page_Load(object sender, EventArgs e)
    {
        Report raReport = new TelerikReport(Request.QueryString["Id"] as int);
        ReportViewer1.Report = raReport;
    }
热情消退 2024-12-13 06:23:12

我将提供另一个简单且适用于 MVC 的答案(2015 年第 3 季度)。

MVC

@(Html
.TelerikReporting()
.ReportViewer()
.Id("reportViewer1")
.ServiceUrl(Url.Content("/Controllers/Reports/"))

//Setting the ReportSource Parameters overrides the default specified in the report.
.ReportSource(new TypeReportSource() { TypeName = @ViewBag.TypeName, Parameters = { new Parameter("startDate", Request.QueryString["startDate"]) } }) 
//To make the query string parameter optional, try:
//.ReportSource(new TypeReportSource() { TypeName = @ViewBag.TypeName, Parameters = { Request.QueryString["startDate"] != null ? new Parameter("startDate", Request.QueryString["startDate"]) : new Parameter() } })

.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
.PersistSession(false)
.PrintMode(PrintMode.AutoSelect)
)

报告没什么特别的。

public TelerikApplicationReport()
{
    InitializeComponent();
}

I will offer another answer that is simple and works for MVC (Q3 2015).

MVC

@(Html
.TelerikReporting()
.ReportViewer()
.Id("reportViewer1")
.ServiceUrl(Url.Content("/Controllers/Reports/"))

//Setting the ReportSource Parameters overrides the default specified in the report.
.ReportSource(new TypeReportSource() { TypeName = @ViewBag.TypeName, Parameters = { new Parameter("startDate", Request.QueryString["startDate"]) } }) 
//To make the query string parameter optional, try:
//.ReportSource(new TypeReportSource() { TypeName = @ViewBag.TypeName, Parameters = { Request.QueryString["startDate"] != null ? new Parameter("startDate", Request.QueryString["startDate"]) : new Parameter() } })

.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
.PersistSession(false)
.PrintMode(PrintMode.AutoSelect)
)

The Report is nothing special.

public TelerikApplicationReport()
{
    InitializeComponent();
}
羁客 2024-12-13 06:23:12

这是另一个例子。将参数直接传递到报告。

在 Asp.net 页面中

protected void Button1_Click(object sender, EventArgs e)
        {
            var instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = new SampleReport(TextBox1.Text);
            this.ReportViewer1.ReportSource = instanceReportSource;
        }

在报告中

public partial class SampleReport : Telerik.Reporting.Report
    {
        public SampleReport(string invoiceNumber)
        {           
            InitializeComponent();


        }
    }

This is another example. Pass parameters directly to the report.

In Asp.net page

protected void Button1_Click(object sender, EventArgs e)
        {
            var instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = new SampleReport(TextBox1.Text);
            this.ReportViewer1.ReportSource = instanceReportSource;
        }

In report

public partial class SampleReport : Telerik.Reporting.Report
    {
        public SampleReport(string invoiceNumber)
        {           
            InitializeComponent();


        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文