Using Crystal Report to view reports on the site and noe able to pass parameters succesfully.
Heres the code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="MATReports.Report" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
body {
width: 950px 950px;
display: inline;
text-align: center;
align-self: center;
}
table {
width: 950px 950px;
display: inline;
text-align: center;
align-self: center;
}
</style>
<script type="text/javascript" src="/crystalreportviewers13/js/crviewer/crv.js"></script>
</head>
<body>
<form id="form1" runat="server" >
<div>
<table>
<tr>
<td><asp:Label ID="Label1" runat="server" Text="PO"></asp:Label></td>
<td><asp:TextBox ID="po" Text="" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="Label2" runat="server" Text="MRR"></asp:Label></td>
<td><asp:TextBox ID="mrrT" Text="" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td><asp:button ID="submit" Text="Run Report" runat="server" OnClick="submit_Click" /></td>
</tr>
</table>
</div>
<br />
<hr />
<br />
<div id="report" runat="server" visible="false">
<table>
<tr>
<td>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True"
ReportSourceID="CrystalReportSource1" ToolPanelWidth="150px" ToolPanelView="ParameterPanel" ShowAllPageIds="True" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="reports\MatRecReport-new.rpt">
</Report>
</CR:CrystalReportSource>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
C#
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace MATReports
{
public partial class Report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//login so users wont have to enter user/pass all the time
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("D:\\Desktop\\MatRecReport-new.rpt");
crConnectionInfo.ServerName = "eCMS4.0";
crConnectionInfo.DatabaseName = "";
crConnectionInfo.UserID = "user";
crConnectionInfo.Password = "pass";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();
}
protected void submit_Click(object sender, EventArgs e)
{
report.Visible = true;
ParameterFields paramFieldsPO = new ParameterFields();
ParameterFields paramFieldsMRR = new ParameterFields();
ParameterField ponum = new ParameterField();
ParameterField mmrr = new ParameterField();
ponum.ParameterFieldName = "PO Number";
mmrr.ParameterFieldName = "MRR Number";
ParameterDiscreteValue ponumtext = new ParameterDiscreteValue();
ParameterDiscreteValue mmrrtext = new ParameterDiscreteValue();
ponumtext.Value = po.Text;
mmrrtext.Value = mrrT.Text;
ponum.CurrentValues.Add(ponumtext);
mmrr.CurrentValues.Add(mmrrtext);
paramFieldsPO.Add(ponum);
paramFieldsMRR.Add(mmrr);
CrystalReportViewer1.ParameterFieldInfo = paramFieldsPO;
CrystalReportViewer1.ParameterFieldInfo = paramFieldsMRR;
CrystalReportViewer1.RefreshReport();
}
}
}