0
votes

I'm developing an asp.net web site.

In that web site i need to display a report with the help of crystal report.

Html

<asp:UpdatePanel ID="uPnlMain" runat="server" UpdateMode="Conditional">
    <ContentTemplate> 
        <table>
            <tr>
                <td>
                    <asp:Button ID="btnSave" runat="server" 
                            CssClass="btn" OnClick="btnSave_Click" Text="Show"/>
                </td>
            </tr>
            <tr>
                <td>
                    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />                
                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

Report source code

protected void btnSave_Click(object sender, EventArgs e)
{
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("Reports/crptBalance.rpt"));
        DSBalance dsCustomers = GetData(@"
DECLARE @DateFrom DATETIME;
DECLARE @p_Dt DATETIME;
SELECT @p_Dt = '2013-11-14 00:00:00';
SELECT TOP 1 @DateFrom = vdate FROM tblLedger WHERE fdocid = 1 AND vdate <= @p_Dt ORDER BY vdate DESC;
IF @DateFrom IS NULL BEGIN
    SELECT TOP 1 @DateFrom = OpBalDate FROM tblTrnsOpBalMaster WHERE OpBalDate <= @p_Dt ORDER BY OpBalDate DESC;
END
SELECT Y.Customer,
    CONVERT(VARCHAR,Y.Date,103) AS [Date],
    UPPER(Y.Description) AS Description,
    Y.[Due Days],
    Y.Debit,
    Y.Credit,
    CASE WHEN Y.[Balance] >= 0 THEN Y.[Balance] ELSE -1 * Y.[Balance] END AS [Balance],
    CASE WHEN Y.[Balance] >= 0 THEN 'DR' ELSE 'CR' END AS [TP] FROM 
(
    SELECT X.Customer,
        X.Date,
        X.Description,
        X.[Due Days],
        X.Debit,
        X.Credit,
        X.Debit - X.Credit AS [Balance] FROM 
    (
        SELECT CUS.nm + ',  ' + cus.[add] AS [Customer],
            vdate [Date],
            narration AS [Description],
            DATEDIFF(DAY, vdate, GETDATE()) AS [Due Days],
            CASE WHEN amttype = 'DR' THEN amt ELSE 0.0000 END AS Debit,
            CASE WHEN amttype = 'CR' THEN amt ELSE 0.0000 END AS Credit
        FROM tblledger LED
            LEFT OUTER JOIN tblCustomer CUS ON (LED.acid = CUS.id)
        WHERE acid IN (42,7) AND vdate >= @DateFrom AND vdate < @p_Dt 
    )X
)Y
ORDER BY Y.Customer,Y.Date");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
}

My problem is that when i use crystal report viewer inside a update panel it doesn't show any data in the report.

I mean to say that it shows blank report.

Where as without update panel it works fine.

Can any one tell me what is the problem

2

2 Answers

0
votes

I once tried to do the same thing but I could not. I researched a lot and found nothing so I worked around with another solution.

I created a master page called "Reposrts" and inside jquery used to populate an iframe with another page where it was crystal report.

Like this:

"Reports.aspx"

<div id="frameReport" style="display: none;"></div>
<script type="text/javascript">
    $(document).ready(function () {

        $("a.lnkReportMenu").click(function (e) {
            var idReport = $(this).attr("rel");

            if (idReport != "0") {
                $('#frameReport').html('<iframe id="ifrReport" width="99%" height="980px" src="Report.aspx?idReport=' + idReport + '">');
                $('#frameReport').show();

                e.preventDefault();
            }
        });
    });
</script>

"Report.aspx"

<%@ Page Language="C#" AutoEventWireup="true" Theme="theme" CodeFile="Report.aspx.cs"
    Inherits="Report" Title="Crystal Report" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<head></head>
<body>
    <form id="ReportCrystal" runat="server">
    <div>
        <CR:CrystalReportViewer ID="crvReport" runat="server" AutoDataBind="true" />
    </div>
    </form>
</body>

"Report.aspx.cs"

private void ReportParameter()
{
    string reportName = "Test.rpt";
    string reportPath = Server.MapPath(String.Concat("~/reports/", reportName));
    string serverName = System.Configuration.ConfigurationManager.AppSettings["db"].ToString();
    string databaseName = String.Empty;
    string userId = Session["USERNAME"].ToString();
    string password = Session["PASSWORD"].ToString();

    if (File.Exists(reportPath))
    {
        ReportDocument reportDoc = new ReportDocument();
        reportDoc.Load(reportPath);

        foreach (ParameterField paramField in reportDoc.ParameterFields)
        {
            paramField.CurrentValues.Clear();
        }

        reportDoc.SetDatabaseLogon(userId, password, serverName, databaseName);

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.Type = ConnectionInfoType.SQL;
        crConnectionInfo.AllowCustomConnection = true;
        crConnectionInfo.IntegratedSecurity = false;
        crConnectionInfo.ServerName = serverName;
        crConnectionInfo.DatabaseName = databaseName;
        crConnectionInfo.UserID = userId;
        crConnectionInfo.Password = password;

        this.ApplyConnection(reportDoc, crConnectionInfo);

        this.crvRelatorio.EnableParameterPrompt = true;
        this.crvRelatorio.ReportSource = reportDoc;
        this.crvRelatorio.RefreshReport();
    }
    else
    {
        this.divHeader.Visible = true;
        this.ltrTitulo.Text = String.Concat("Relatório não foi encontrado ");
    }
}

private void ApplyConnection(ReportDocument report, ConnectionInfo connectionInfo)
{
    this.ApplyLogOnInfo(report, connectionInfo);
    this.ApplyLogOnInfoForSubreports(report, connectionInfo);
}

private void ApplyLogOnInfo(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
    foreach (CrystalDecisions.CrystalReports.Engine.Table tableTemp in reportDocument.Database.Tables)
    {
        if (tableTemp.Name.ToUpper().StartsWith("COMMAND"))
        {

        }

        TableLogOnInfo tableLogonInfo = tableTemp.LogOnInfo;
        tableLogonInfo.ConnectionInfo = connectionInfo;
        tableTemp.ApplyLogOnInfo(tableLogonInfo);

        bool b = tableTemp.TestConnectivity();
    }
}

private void ApplyLogOnInfoForSubreports(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
    foreach (Section sectionTemp in reportDocument.ReportDefinition.Sections)
    {
        foreach (ReportObject reportObjectTemp in sectionTemp.ReportObjects)
        {
            if (reportObjectTemp.Kind == ReportObjectKind.SubreportObject)
            {
                SubreportObject subreportObject = (SubreportObject)reportObjectTemp;

                ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);

                this.ApplyLogOnInfo(subReportDocument, connectionInfo);
            }
        }
    }
}

private ParameterFields ApplyParameters(string paramName, object paramValue)
{
    ParameterFields paramFields = new ParameterFields();
    ParameterField paramField = new ParameterField();
    paramField.ParameterFieldName = paramName; // Crystal Report Parameter name.

    ParameterDiscreteValue pdvValue = new ParameterDiscreteValue();
    pdvValue.Value = paramValue;

    paramField.CurrentValues.Add(pdvValue);

    paramFields.Add(paramField);

    return paramFields;
}

"web.config"

<system.web>
    <compilation>
        <assemblies>
            <add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        </assemblies>
    </compilation>
</system.web>
0
votes

I think you are missing the Report Source in the update panel, which is why it may not work. On the other hand, Crystal reports don't seem to work very well in Update Panels. I personally have never tried it (I built a Reports Portal but used separate pages) but have read quite a bit about it. Even when people get it to display in the update panel, often times the print and export buttons on the toolbar won't work. This post is very informative and suggests several different solutions you could pursue to get an acceptable solution.