0

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

4

2 に答える 2

0

私も一度同じことをしようとしましたが、できませんでした。私は多くのことを調査しましたが、何も見つからなかったので、別の解決策を試しました。

「Reposrts」というマスターページを作成し、jquery 内で iframe に Crystal Report である別のページを設定していました。

このような:

「レポート.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>

「レポート.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>
于 2013-11-14T12:42:34.290 に答える
0

更新パネルにレポート ソースが表示されていないため、機能しない可能性があります。一方、Crystal レポートは更新パネルではうまく機能しないようです。個人的には試したことはありませんが (Reports Portal を作成しましたが、別のページを使用しました)、かなりの量の記事を読みました。更新パネルに表示するようになったとしても、ツールバーの印刷ボタンとエクスポート ボタンが機能しないことがよくあります。この投稿は非常に有益であり、許容できる解決策を得るために追求できるいくつかの異なる解決策を提案しています。

于 2013-11-14T13:59:41.237 に答える