2011-09-22 99 views
3

问题: 我想在页面上传递从查询字符串报表参数值,以我的报告已定义的参数。我似乎无法获得通过报告一路通过的价值。Telerik报告|设置报表参数通过查询字符串

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

     ReportViewer.Report = report; 

上面这个语法是好的,但是当变量“报告”由TelerikReport()创建构造它不具有该参数的值,但,当我事后设置这似乎并不重要。即使我尝试调用ReportViewer.RefreshReport()

地方我已经看过:

感谢您的帮助,

克里斯

回答

2

我能够得到它通过改变构造器的MyCustomReportLibrary.TelerikReport工作。希望这有助于任何寻找答案的人。

就像这个例子 Telerik Forums | Pass Report parameters from Rad window to a telerik report

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; 
    } 
0

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

在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(); 


     } 
    } 
1

我将提供另一种答案是简单而适用于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) 
) 

的报告是没有什么特别的。

public TelerikApplicationReport() 
{ 
    InitializeComponent(); 
} 
+0

我当时没有使用mvc,看起来像是会工作得很好 –