This sample project demonstrates how to connect to data from the code. First, let's connect to data for the viewer:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Viewer.aspx.cs" Inherits="Connect_to_Data_from_the_Code.Viewer" %>
<%@ Register assembly="Stimulsoft.Report.Web" namespace="Stimulsoft.Report.Web" tagprefix="cc1" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
		<cc1:StiWebViewer ID="StiWebViewer1" runat="server"
			OnGetReport="StiWebViewer1_GetReport" />
	</form>
</body>
</html>

Use Load() method to load the report template and delete all connections with Clear():
protected void StiWebViewer1_GetReport(object sender, StiReportDataEventArgs e)
{
	// Loading the report template
	var reportPath = Server.MapPath("Reports/SimpleList.mrt");
	var report = new StiReport();
	report.Load(reportPath);

 	// Deleting connections in the report template
	report.Dictionary.Databases.Clear();

...

After that, load data from the XML file using ReadXml() and register it in the report with RegData():
...

	// Loading data from the XML file
	var dataPath = Server.MapPath("Data/Demo.xml");
	var data = new DataSet();
	data.ReadXml(dataPath);

	// Registering data in the report
	report.RegData(data);

	// Syncing the data structure, if required
	//report.Dictionary.Synchronize();

	e.Report = report;
}

Now, let's try with Designer:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Designer.aspx.cs" Inherits="Connect_to_Data_from_the_Code.Designer" %>
<%@ Register assembly="Stimulsoft.Report.WebDesigner" namespace="Stimulsoft.Report.Web" tagprefix="cc1" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
		<cc1:StiWebViewer ID="StiWebDesigner1" runat="server"
			OnGetReport="StiWebDesigner1_GetReport"
			OnPreviewReport="StiWebDesigner1_PreviewReport" />
	</form>
</body>
</html>

First, load the report template:
protected void StiWebDesigner1_GetReport(object sender, StiReportDataEventArgs e)
{
	// Loading the report template
	var reportPath = Server.MapPath("Reports/SimpleList.mrt");
	var report = new StiReport();
	report.Load(reportPath);

	e.Report = report;
}

...

After that, get a preview report and delete all connections in the report template:
...

protected void StiWebDesigner1_PreviewReport(object sender, StiReportDataEventArgs e)
{
	// Getting a preview report
	var report = e.Report;

	// Deleting connections in the report template
	report.Dictionary.Databases.Clear();


...

Then, load data from the XML file:
...
	// Loading data from the XML file
	var dataPath = Server.MapPath("Data/Demo.xml");
	var data = new DataSet();
	data.ReadXml(dataPath);

	// Registering data in the report
	report.RegData(data);

	// Syncing the data structure, if required
	//report.Dictionary.Synchronize();
}

In the screenshot below you can see the result of the sample code:

Connecting to Data from Code

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.