如何使用telerik报告的客户数据源添加过滤器?

时间:2013-12-23 08:27:11

标签: asp.net datasource telerik-reporting

我将报告的数据源设置在显示报告的页面的后台。代码如下:

protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               string acceptedStatus = QuoteStatusEnum.Accepted.ToString();
               string rejectedStatus = QuoteStatusEnum.Rejected.ToString();
               string canceledStatus = QuoteStatusEnum.Canceled.ToString();
               IList<QuoteRequest> list = ServiceFactory.QuoteRequestService.QueryItems(p => (p.QuoteRequestStatus.QuoteRequestStatusName == acceptedStatus) ||
                                                                                       (p.QuoteRequestStatus.QuoteRequestStatusName == rejectedStatus) ||
                                                                                       (p.QuoteRequestStatus.QuoteRequestStatusName == canceledStatus)).OrderBy(p => p.CreatedBy).ToList();
               var data = from d in list
                          select new
                          {
                              ClientName = d.Client.CompanyName,
                              Client = d.Client.ClientID,
                              CompanyName = d.Client.CompanyName,
                              QuoteNumber = d.QuoteNumber,
                              PropertyAddress = d.Property.PropertyAddressLine1 + (string.IsNullOrEmpty(d.Property.PropertyAddressLine2) ? "" : " ," + d.Property.PropertyAddressLine2),
                              QuotePrice = d.QuotePrice.HasValue ? d.QuotePrice.Value : 0,
                              ClientContact = ServiceFactory.ContactService.Read(p => p.ContactID == d.ClientContactID).FirstName + " " + ServiceFactory.ContactService.Read(p => p.ContactID == d.ClientContactID).LastName,
                              IsConverted = d.QuoteRequestStatus.QuoteRequestStatusName == "Accepted" ? "Yes" : "No",
                              ModifiedDate = d.ModifiedDate ?? DateTime.Now.AddYears(-10)
                          };

               int pastDueCount = list.Count(p => p.ClientDueDate < DateTime.Today);

               var instanceReporSouce = new InstanceReportSource();
               instanceReporSouce.ReportDocument = new CompletedQuotesReport();

               instanceReporSouce.ReportDocument.Reports.First().DataSource = data;
               ReportViewer1.ReportSource = instanceReporSouce;
           }
       }

现在,我想在报表中添加一些过滤器。就像通过使用“Fields.XX = parameter.value”表达式在设计视图中添加过滤器的效果一样,因为现在报表中没有数据源,所以它不能使用'Fields.XX ......'表达式。如何通过后台的程序实现我的目标。顺便说一下,我尝试按代码添加参数:

instanceReporSouce.ReportDocument.Reports.First().ReportParameters.Add(new ReportParameter("TotalAccepted", ReportParameterType.String, "TotalAccepted:" + list.Count(p => p.QuoteRequestStatus.QuoteRequestStatusName == acceptedStatus)));

我可以获得参数。但仍无法过滤数据。我该如何解决这个问题?

任何建议表示赞赏, 最好的祝福, 汤。

1 个答案:

答案 0 :(得分:0)

 private void RegisterByDept_NeedDataSource(object sender, EventArgs e)
    {
        string groupBy = string.Empty;
        string sortBy = string.Empty;

        Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
        var payoutUID = report.Parameters["payoutUID"].Value.ToString();
        // some code here...
    }