To Display the Report on Microsoft Report Viewer following are the steps:
Step 1 : Add the Microsoft Report Viewer from Reporting tab of the Tool Box.
Step 2: On "Show" Button Click display the report.
On button click we provide the Report Viewer parameters to display the appropriate report with respect to the data provided using the dropdownlist.
In the above figure Fig 2, the user selects the details from the dropdownlist and is passed as parameter on "Show" button click.
Step 3: Code to be written on Show Button Click event.
protected void btnShow_Click(object sender, EventArgs e)
{
try
{
ReportParameter[] parm = new ReportParameter[2];
parm[0] = new ReportParameter("<BatchYear>", ddlBatch.SelectedValue);
parm[1] = new ReportParameter("<ProgramCode>", ddlProgramName.SelectedValue);
ReportViewer1.ShowCredentialPrompts = false;
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials(UserId, Password, DomainName);
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new System.Uri(ReportServerUrl);
ReportViewer1.ServerReport.ReportPath = "//<ReportPath>";
ReportViewer1.ServerReport.SetParameters(parm);
ReportViewer1.ServerReport.Refresh();
}
catch (Exception ex)
{
DisplayAJAXMessage(this,"Error:: "+ex);
}
}
static public void DisplayAJAXMessage(Control page, string msg)
{
string myScript = String.Format("alert('{0}');", msg);
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);
}
Note: The text shown in bold need to added as per requirement
Step 1 : Add the Microsoft Report Viewer from Reporting tab of the Tool Box.
![]() |
Fig : To Add Report Viewer in the Design Page. |
Step 2: On "Show" Button Click display the report.
On button click we provide the Report Viewer parameters to display the appropriate report with respect to the data provided using the dropdownlist.
![]() |
Fig 2: Report Display |
Step 3: Code to be written on Show Button Click event.
protected void btnShow_Click(object sender, EventArgs e)
{
try
{
ReportParameter[] parm = new ReportParameter[2];
parm[0] = new ReportParameter("<BatchYear>", ddlBatch.SelectedValue);
parm[1] = new ReportParameter("<ProgramCode>", ddlProgramName.SelectedValue);
ReportViewer1.ShowCredentialPrompts = false;
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials(UserId, Password, DomainName);
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new System.Uri(ReportServerUrl);
ReportViewer1.ServerReport.ReportPath = "//<ReportPath>";
ReportViewer1.ServerReport.SetParameters(parm);
ReportViewer1.ServerReport.Refresh();
}
catch (Exception ex)
{
DisplayAJAXMessage(this,"Error:: "+ex);
}
}
static public void DisplayAJAXMessage(Control page, string msg)
{
string myScript = String.Format("alert('{0}');", msg);
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);
}
Note: The text shown in bold need to added as per requirement

No comments:
Post a Comment