I am trying to pass parameter from one page to another page. I am using CrystalReportViewer
on the other page.
There is CrystalReportViewer1_Init(object sender, EventArgs e)
function, there I should receive the filename
from the previous page
Here is my code
protected void CrystalReportViewer1_Init(object sender, EventArgs e)
{
ReportDocument _rdStudents = new ReportDocument();
string reportPath = Server.MapPath("~/CrystalReportFiles/Inventory/" + Request.QueryString[" filename "].ToString());
//string reportPath = Server.MapPath("~/CrystalReportFiles/Inventory/WeightBarcorde.rpt"); This code is working
_rdStudents.Load(reportPath);
CrystalReportViewer1.ReportSource = _rdStudents;
}
Here is my parameter http://localhost:55047/CrytalReportTest.aspx?filename=WeightBarcorde.rpt
<a target="_blank" href="CrytalReportTest.aspx?filename=WeightBarcorde.rpt">WeightBarcorde.rpt</a>
Can we pass parameter inside init function? or What is wrong in my code
Remove the white spaces from your query string.
Change:
Request.QueryString[" filename "]
to:
Request.QueryString["filename"]
Write to the VS output console to see if it's actually reading the parameter:
System.Diagnostics.Debug.WriteLine(reportPath);
This answer could also help:
https://stackoverflow.com/a/2827025/1821637