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

Filter in Report Designer .trdx

3 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rubens
Top achievements
Rank 1
Rubens asked on 26 Sep 2013, 02:10 AM

Good evening, I managed to create a report in Report Designer and present data using a SQL Server wiht connectionString, but I'm having a little difficulty passing filter and display only the filtered data. What is missing in the code below so that the filter would start working.

private void Window_Loaded_1 (object sender, RoutedEventArgs e)
         {
             Telerik.Reporting.UriReportSource Telerik.Reporting.UriReportSource ur = new ();
             ur.Uri = System.IO.Path.Combine (Environment.CurrentDirectory "Report1.trdx");
             myReport.ReportSource = ur;
         / / Need to filter
             / *
             Telerik.Reporting.Filter filter1 Telerik.Reporting.Filter = new ();
             filter1.Expression = "Fields.Pro_codigo =";
             filter1.Operator = Telerik.Reporting.FilterOperator.Equal;
             filter1.Value = "= 00002";
             * /
         }

graciously
André

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 30 Sep 2013, 01:37 PM
Hello Rubens,

In order to change the report definition of the .trdx report you will need to deserialize the .trdx file. Following is an example code of this process:
var settings = new System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace = true;
   
using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create("Report1.trdx", settings))
{
    var xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
   
    var report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
   
    //applying filtering
    Telerik.Reporting.Filter filter1 = new Telerik.Reporting.Filter();
    filter1.Expression = "Fields.Pro_codigo";
    filter1.Operator = Telerik.Reporting.FilterOperator.Equal;
    filter1.Value = "= 00002";
     
    report.Filters.Add(filter1);
   
    this.reportViewer1.ReportSource = new InstanceReportSource
    {
        ReportDocument = report,
    };
}

However, you can apply filtering during design time using the Report Designer, which is easier and doesn't require any custom code. For more information please follow the How to: Add filtering to Report help article.

If your goal is to filter the data at runtime based on a user input you can use report parameters. This approach is described in the Using Parameters with the SqlDataSource component help article.

Regards,
Nasko
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Vishnu
Top achievements
Rank 1
answered on 08 Jan 2014, 08:36 AM
i am using the same thing in vb.net. But the xmlReader object is returning Nothing. So no report is loading

Dim settings As New XmlReaderSettings()
        settings.IgnoreWhitespace = True
        Dim myReportBook As Telerik.Reporting.ReportBook = New Telerik.Reporting.ReportBook

        Using xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create(Server.MapPath(strFilePath), settings)
            Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
            Dim reportWMS As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize(xmlReader), Telerik.Reporting.Report)

            With reportWMS
                .DocumentMapText = ""
                .ReportParameters("projectNo").Value = _projectNo
                .ReportParameters("dnHeaderNo").Value = _value
                .ReportParameters("transferType").Value = _TransferType
                ReportViewer1.DocumentMapVisible = False
                ReportViewer1.ShowDocumentMapButton = False
            End With

            myReportBook.Reports.Add(reportWMS)
        End Using

        Dim reportSource = New Telerik.Reporting.InstanceReportSource
        reportSource.ReportDocument = myReportBook
        ReportViewer1.ReportSource = reportSource
        ReportViewer1.RefreshReport()
0
Ivan Hristov
Telerik team
answered on 10 Jan 2014, 01:12 PM
Hello Vishnu,

Your code runs fine and the InstanceReportSource gets created properly.

Actually given your code It is highly unlikely the XmlReader to be Nothing after executing XmlReader.Create() method. In case the supplied file path is invalid, there should be an exception thrown. Please check if there are some exceptions that you catch later so your code execution never gets to the deserialization part.

Regards,
Ivan Hristov
Telerik

New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

Tags
General Discussions
Asked by
Rubens
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Vishnu
Top achievements
Rank 1
Ivan Hristov
Telerik team
Share this question
or