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

Binding datasource for a deserialized report

1 Answer 164 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ravi Theja
Top achievements
Rank 1
Ravi Theja asked on 10 Feb 2016, 02:23 PM
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.

Thanks

 
 
private void button6_Click(object sender, RoutedEventArgs e)
        {
            try
            {
 
                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();
                    document.Load("C:/Temp/XML/ReportInside.xml");
 
                    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";
                                }
                            }
                        }
                    }
 
                    document.Save(xmlWriter);
 
                }
 
                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 };
 
                rvw.ReportViewer1.RefreshReport();
                rvw.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
 
        }

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 12 Feb 2016, 02:48 PM
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.

Regards,
Stef
Telerik
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
Tags
General Discussions
Asked by
Ravi Theja
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or