Posted 29 August 2018, 6:21 pm EST
Hello Carolyn,
You can create the Report id according to the runtime parameters as follow:
<script type="text/javascript">
$(function () {
GrapeCity.ActiveReports.Viewer({
element: '#viewerContainer',
reportService: {
url: 'http://localhost:50058/WebService1.asmx'
},
report: { id: 'rpt_Bind.rpx?Country=\'USA\',City=\'Portland\'' },
uiType: 'desktop'
});
});
After, create the custom report service to set the parameter in the report data source as follow:
public class WebService1 : GrapeCity.ActiveReports.Web.ReportService
{
[WebMethod]
protected override object OnCreateReportHandler(string reportPath)
{
string reportname = reportPath.Substring(0,reportPath.IndexOf('?'));
if (reportname == "rpt_Bind.rpx")
{
// Separate the parameter from the string in form of Key and Value
string parameters = reportPath.Substring(reportPath.IndexOf('?') + 1);
string[] parameterList = parameters.Split(',');
Hashtable ht = new Hashtable();
foreach (string t in parameterList)
{
string[] parameter = t.Split('=');
ht.Add(parameter[0], parameter[1]);
}
//Constructs the SQl Query
string cmdText = "Select * From Customers Where ";
foreach (DictionaryEntry t in ht)
{
cmdText = cmdText + t.Key.ToString() + "=" + t.Value.ToString() + "AND ";
}
cmdText = cmdText.Substring(0, cmdText.Length - 4);
OleDbConnection connect = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\mohitg\Documents\GrapeCity Samples\ActiveReports 12\Data\NWIND.mdb; Persist Security Info = False");
//set up connection string
OleDbCommand command = new OleDbCommand(cmdText, connect);
//middle tier to run connect
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dset = new DataTable();
da.Fill(dset);
GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "/rpt_Bind.rpx");
sectionReport.LoadLayout(xtr);
xtr.Close();
sectionReport.DataSource = dset;
return sectionReport;
}
else
return base.OnCreateReportHandler(reportPath);
}
}
hope it helps.
Thanks,