This is a migrated thread and some comments may be shown as answers.

Telerik Report Filter not working dynamically

3 Answers 369 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Jahangeer
Top achievements
Rank 1
Jahangeer asked on 22 Jan 2015, 12:16 PM
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 :(



3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 24 Jan 2015, 04:56 PM
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.

 
0
Masaab
Top achievements
Rank 1
answered on 10 Mar 2015, 02:04 AM
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);
0
Stef
Telerik team
answered on 10 Mar 2015, 05:59 PM
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.

 
Tags
Report Designer (standalone)
Asked by
Jahangeer
Top achievements
Rank 1
Answers by
Stef
Telerik team
Masaab
Top achievements
Rank 1
Share this question
or