Binding datasource for a deserialized report

2 posts, 0 answers
  1. Ravi Theja
    Ravi Theja avatar
    1 posts
    Member since:
    Feb 2016

    Posted 10 Feb 2016 Link to this post

    I am trying to change report definition dynamically but unable to bind datasource. Could you please help me in binding the datasource dynamically. I amusing LinqtoSQL as datasource.


    1. On click of a button, I am calling the constructor of my report and getting the report document and setting it to InstantReportSource's report document.
    2. I am serializing the report document to XML file and making modifying the report definition.
    3. After deserializing, how to bind the datasource before inputting the report to report viewer.


    private void button6_Click(object sender, RoutedEventArgs e)
                    ReportViewerWindow rvw = new ReportViewerWindow();
                    Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
                    instanceReportSource.Parameters.Add("ParamDivisionId", null);
                    instanceReportSource.Parameters.Add("ParamStartDate", new DateTime(2014, 1, 1));
                    instanceReportSource.Parameters.Add("ParamEndDate", new DateTime(2014, 2, 1).AddMinutes(-1));
                    instanceReportSource.ReportDocument = new DispatchAnywhere3.Reports.Report1(_user, _repository, _adminRepo);
                    using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create("C:/Temp/XML/ReportInside.xml"))
                        Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
                            new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
                        xmlSerializer.Serialize(xmlWriter, instanceReportSource.ReportDocument);
                    using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create("C:/Temp/XML/ReportInsideSecond.xml"))
                        XmlDocument document = new XmlDocument();
                        XmlNodeList nodes = document.ChildNodes;
                        foreach (XmlNode node in nodes)
                            if (node.Name == "Report")
                                XmlNodeList nodes1 = node.ChildNodes;
                                foreach(XmlNode node2 in nodes1)
                                    if (node2.Name == "Style")
                                   node2.Attributes["BackgroundColor"].Value = "Red";
                    Telerik.Reporting.Report report = null;
                    using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create("C:/Temp/XML/ReportInsideSecond.xml"))
                        Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
                            new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
                         report = xmlSerializer.Deserialize(xmlReader) as Telerik.Reporting.Report ;
                    rvw.ReportViewer1.ReportSource = new InstanceReportSource { ReportDocument = report };
                catch (Exception ex)
                    MessageBox.Show(ex.ToString(), "error", MessageBoxButton.OK, MessageBoxImage.Error);
  2. Stef
    Stef avatar
    3611 posts

    Posted 12 Feb 2016 Link to this post

    Hello Ravi,

    If you need to change the report definition, the recommended approach is to work with the report instance (Telerik.Reporting.Report object).

    Through the report instance you have access to each item,section or property in the report. Items can be searched in the report by using the Find method.
    For example:
    var report = new MyReport();
    report.DataSource = GetData();
    var table = report.Items.Find("table1",true)[0] as Telerik.Reporting.Table;
    table.DataSource = GetOtherData();
    report.Style.BackgroundColor= Color.Red;
    //and etc

    Changes in the report instance will be serialized in XML - Serializing Report Definition in XML, where custom data objects or properties will not be included. You can serialize the settings of a data source component.

    I hope this information helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top