Telerik Report Filter not working dynamically

4 posts, 0 answers
  1. Jahangeer
    Jahangeer avatar
    19 posts
    Member since:
    Apr 2013

    Posted 22 Jan 2015 Link to this post

    Hi,

    I have created trdx file from telerik Report designer and I have added a table layout with columns from sql datasource now I want to access it my ASP.NEt application there I have used this code 

     var settings = new System.Xml.XmlReaderSettings();
            settings.IgnoreWhitespace = true;

            using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create("C:\\Lisensining\\Report1.trdx", settings))
            {
                var xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
                var reportDocument = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
                var reportSource = new InstanceReportSource();
          
                reportSource.ReportDocument = reportDocument;

                
                SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
                scsb.UserID = "sa";
                scsb.Password = "root";
                scsb.InitialCatalog = DataBaseName;
                scsb.DataSource = SErverName;
                Telerik.Reporting.SqlDataSource sds = (Telerik.Reporting.SqlDataSource)reportDocument.DataSource;
                if (sds != null)
                    sds.ConnectionString = scsb.ConnectionString;

                this.SetConnectionString(reportDocument.Items, connectionString);
     
             
                this.ReportViewer1.ReportSource = reportSource;
                this.ReportViewer1.RefreshReport();
                
             
            }

    It is working great and showing all the records from database table  but as I add filters to code report does not show any record
     Telerik.Reporting.Filter filter1 = new Filter("Fields.[ProductName]", FilterOperator.Equal, "Vista");
                reportDocument.Filters.Add(filter1);  

    Now report viewer does not show any thing :(



  2. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 24 Jan 2015 Link to this post

    Hello Jahangeer,

    In the given filter expression is missing an equal sign before "Fields.[ProductName]", which equal sign is used by the reporting engine to distinguish expressions from simple string input.

    My recommendation is to validate any run-time changes in reports by serializing the Telerik.Reporting.Report instance in XML (TRDX file) and to preview it with the Standalone Report Designer.
    Other approach is to use test data and create simple report with the integrated in VS Report Designer, and re-use the auto-generated code in the report's designer.cs(vb) file.


    I hope the provided information is helpful.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Masaab
    Masaab avatar
    15 posts
    Member since:
    Nov 2013

    Posted 09 Mar 2015 in reply to Stef Link to this post

    I am trying to filter programatically but its not working. I am having an CalculatedField UpTimePercentage which needs to be compared to my nmtxtupTimePercent value which is an numericTextbox. If I dont use filter the report works fine.

      Telerik.Reporting.Filter filter = new Telerik.Reporting.Filter();<br>                filter.Expression = "=Fields.UpTimePercentage";<br>                filter.Operator = Telerik.Reporting.FilterOperator.LessThan;<br>                filter.Value = string.Format("={0}", this.nmtxtupTimePercent.Value.ToString());<br>                this.Report.Filters.Add(filter);
      Telerik.Reporting.Filter filter = new Telerik.Reporting.Filter();
                    filter.Expression = "=Fields.UpTimePercentage";
                    filter.Operator = Telerik.Reporting.FilterOperator.LessThan;
                    filter.Value = string.Format("={0}", this.nmtxtupTimePercent.Value.ToString());
                    this.Report.Filters.Add(filter);
  5. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 10 Mar 2015 Link to this post

    Hi Massab,

    The filter criteria in your code snippet will use the string set as nmtxtupTimePercent.Value, not the TextBox evaluated expression. To create the filter expression use the expression used as nmtxtupTimePercent.Value directly.
    For example:
                   //in the report definition
                  this.nmtxtupTimePercent.Value="=Fields.X";
                  Telerik.Reporting.Filter filter = new Telerik.Reporting.Filter();
                    filter.Expression = "=Fields.UpTimePercentage";
                    filter.Operator = Telerik.Reporting.FilterOperator.LessThan;
                    filter.Value ="=Fields.X";
                    this.Filters.Add(filter);
     
    //on displaying the report
    var report = new MyReport();//create an instance of the report
    //wrap it in a report source
    var IRS = new InstanceReportSource {ReportDocument = report};
    //display the report
    reportViewer1.ReportSource= IRS;


    I hope the provided information is helpful.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top