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.
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.I am serializing the report document to XML file and making modifying the report definition.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); } }