【问题标题】:Telerik Report in Asp.Net-Apply Filters in programaticallyAsp.Net 中的 Telerik 报告 - 以编程方式应用过滤器
【发布时间】:2016-03-12 08:38:00
【问题描述】:

我的要求:通过 c# 编码(非设计)应用填充物,即过滤器工资大于 7000。

我的项目中有一个类库和一个 Web 表单。 我正在创建关于类库的报告并使用 Web 表单显示报告。

当我运行我的应用程序时,它总是显示未过滤的数据。 我如何在查看器中获取过滤数据。

代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Telerik.Reporting.Filter f1 = new Telerik.Reporting.Filter();
        f1.Expression = "= Fields.Salary";
        f1.Operator = Telerik.Reporting.FilterOperator.GreaterOrEqual;
        f1.Value = "=7000";
        EmpReport objEmpReport = new EmpReport(); objEmpReport.Filters.Add(f1);
        TypeReportSource rptSource = new TypeReportSource(); rptSource.TypeName = typeof(EmpReport).AssemblyQualifiedName; this.ReportViewer1.ReportSource = rptSource;
    }
}

【问题讨论】:

    标签: c# asp.net filter telerik


    【解决方案1】:

    工作代码:

    // ...
    using Telerik.Reporting;
    using Telerik.Reporting.Processing;
    // ...
    
    void ExportToPDF(string reportToExport)
    {
        // all my reports are in trdx format - detect file type and use unpackage below for trdp files.
        string currPath = HttpRuntime.AppDomainAppPath;                 // get the full path so deserialise works
        reportToExport = currPath + @"Reports\" + reportToExport;       // add folder and report name to path
        UriReportSource uriReportSource = new UriReportSource { Uri = reportToExport };   // compressed to 1 line for brevity
        Telerik.Reporting.Report myReport = DeserializeReport(uriReportSource);    // extract report from xml format (trdx)
    
        // Filters are client side (use params for server side) Here we work with the report object.
        // set meaningful field name and values for your code, maybe even pass in as params to this function...
        myReport.Filters.Add("UserId", FilterOperator.Equal , "1231");
    
        var instanceReportSource = new Telerik.Reporting.InstanceReportSource();    // report source
        instanceReportSource.ReportDocument = myReport;         // Assigning Report object to the InstanceReportSource
    
        // kinda optional, lots of examples just used null instead for deviceInfo
        System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();   // set any deviceInfo settings if necessary
    
        ReportProcessor reportProcessor = new ReportProcessor();                        // will do work
        RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);   // GO!
    
        if (!result.HasErrors)
        {
            this.Response.Clear();
            this.Response.ContentType = result.MimeType;
            this.Response.Cache.SetCacheability(HttpCacheability.Private);
            this.Response.Expires = -1;
            this.Response.Buffer = true;
            this.Response.BinaryWrite(result.DocumentBytes);
            this.Response.End();
        }
        else
        {
            Exception[] ex = result.Errors;
            throw new Exception(ex[0].Message);
        }
    }
    
    Telerik.Reporting.Report DeserializeReport(UriReportSource uriReportSource)
    {
        var settings = new System.Xml.XmlReaderSettings();
        settings.IgnoreWhitespace = true;
        using (var xmlReader = System.Xml.XmlReader.Create(uriReportSource.Uri, settings))
        {
            var xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
            var report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
            return report;
        }
    }
    
    Telerik.Reporting.Report UnpackageReport(UriReportSource uriReportSource)
    {
        var reportPackager = new ReportPackager();
        using (var sourceStream = System.IO.File.OpenRead(uriReportSource.Uri))
        {
            var report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
            return report;
        }
    }
    

    【讨论】:

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