We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to edit a report at runtime

Platform: Silverlight |
Control: ReportViewer

A report (RDL/RDLC) can be edited or modified at runtime using ReportDefinition class. The following describes the steps to edit a report at runtime and render the output.

  1. To edit existing report, it need to be de serialized to Report Definition object using XmlSerializer.


FileStream stream = new FileStream(info.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
XElement rdl = XElement.Load(XmlReader.Create(stream));
string Namespace = (from attribute in rdl.Attributes() where attribute.Name.LocalName == "xmlns" select attribute.Value).FirstOrDefault();
XmlSerializer xs = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), Namespace);
using (StringReader reader = new StringReader(rdl.ToString()))
   reportDefinition = (Syncfusion.RDL.DOM.ReportDefinition)xs.Deserialize(reader);
  1. The serialized report definition object contains all the properties available in report file. The properties of each XML element can accessed and updated to required values. In the below code, value of a text box report item in page header is updated with new value.


var data = reportDefinition.ReportSections[0];
//=====Edit Report item in report header =========//
Syncfusion.RDL.DOM.TextBox headertext = new Syncfusion.RDL.DOM.TextBox();
headertext = (Syncfusion.RDL.DOM.TextBox)data.Page.PageHeader.ReportItems[0];
headertext.Paragraphs[0].TextRuns[0].Value = table.Columns[0].ToString();
  1. The below code used to edit Tablix report item and its inner cell element value in report.


Syncfusion.RDL.DOM.Tablix reportitem = new Syncfusion.RDL.DOM.Tablix();
reportitem = (Syncfusion.RDL.DOM.Tablix)data.Body.ReportItems[0];            
for (int i = 0; i < table.Columns.Count; i++)
  Syncfusion.RDL.DOM.TextBox txtbox = new Syncfusion.RDL.DOM.TextBox();
  txtbox = (Syncfusion.RDL.DOM.TextBox)reportitem.TablixBody.TablixRows[0].TablixCells[i].CellContents.ReportItem;
  txtbox.Paragraphs[0].TextRuns[0].Value = table.Columns[i].ToString();     
  1. The modified report definition can be converted as stream or saved into a local file using the XmlSerializer’s Deserialize method.


string nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";
if (reportDefinition.RDLType == Syncfusion.RDL.DOM.RDLType.RDL2010)
    nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
System.Xml.Serialization.XmlSerializerNamespaces serialize = new System.Xml.Serialization.XmlSerializerNamespaces();
serialize.Add("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
XmlSerializer xs2 = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), nameSpace);
MemoryStream memoryStream = new MemoryStream();
TextWriter ws2 = new StreamWriter(memoryStream);
xs2.Serialize(ws2, reportDefinition, serialize);
memoryStream.Position = 0;






You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile