c# - 我如何在 Crystal 或 rdlc 报告中绑定(bind) c# 的业务对象?

标签 c# asp.net crystal-reports rdlc

首先让我告诉你一件事,我还没有接触过任何类型的报告。我已经阅读了关于这个主题的所有相关问题和答案。但找不到任何具体的解决方案。

我的问题是我要制作一个非常简单的报告,我必须在其中显示数据库 View 中的一行。为了拥有该行,我创建了一个业务对象(实体)。那个实体完美地控制了我的行。我也尝试过 crystal report 和 rdlc report。但最后我只会选择一个。所以我的解决方案中有一份 Crystal 报告。在我的 aspx 表单中,我使用了一个报告查看器。但我不知道如何让这三样东西一起工作,即报表、报表查看器和保存信息的对象或实体。

代码在这里

Crystal 报表的名字是FormSaleMoneyReceipt.rpt

我的aspx页面是

<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
<div id = "SearchPlace">
    <label for ="">Candidate ID:</label><asp:TextBox runat = "server" ID = "txtCandidateId"></asp:TextBox>
    <label for ="">Form SL#:</label><asp:TextBox runat = "server" ID = "txtFormSl"></asp:TextBox>
    <asp:Button runat = "server" ID = "btnShowReport" Text = "Show Report" 
        onclick="btnShowReport_Click" />
</div>
<div id = "ReportViewrHolder">
    <CR:CrystalReportViewer ID="CrystalReportViewerMRN" runat="server" AutoDataBind="true" />
</div>
</form>

我的文件隐藏代码是

protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnShowReport_Click(object sender, EventArgs e)
{
    int candidateId = 0;

    string formSl = txtFormSl.Text;
    ViewFormSaleMoneyReceiptEntity formSaleMoneyReceiptEntity = new ViewFormSaleMoneyReceiptEntity();
    if(txtCandidateId.Text != "")
    {
        candidateId = Convert.ToInt32(candidateId);
        formSaleMoneyReceiptEntity = ViewFormSaleMoneyReceipt_DAO.GetMoneyReceiptByID(candidateId);
        //CrystalReportViewerMRN.ReportSource = formSaleMoneyReceiptEntity; 
    }
    if(txtFormSl.Text!="")
    {
        formSaleMoneyReceiptEntity = ViewFormSaleMoneyReceipt_DAO.GetMoneyReceiptByFormSL(formSl);
        //CrystalReportViewerMRN.ReportSource = formSaleMoneyReceiptEntity; 
    }
}

拜托,请给我一个解决方案,我非常需要解决方案。预先感谢所有聪明的技术极客。

最佳答案

您必须创建一个ReportSource 对象并将其分配给您的报告,如here 所述.

CrystalReportViewerMRN.ReportSource = myReportSource;

关于c# - 我如何在 Crystal 或 rdlc 报告中绑定(bind) c# 的业务对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7512093/

相关文章:

c# - 使用 HttpClient 子类的类型化客户端

c# - 从头开始为商业应用预订 ASP.NET MVC

stored-procedures - Crystal Reports 无法识别已将新参数添加到报告存储过程中

asp.net - MVC 3 直通路由

asp.net - 使加密字符串与输入字符串长度相同?

mysql - 属性 'ReportSource' 是 'ReadOnly'

crystal-reports - 抑制没有数据和标题的子报表

c# - 反转字符串数组的元素

c# - 在 .net 控制台应用程序中显示消息框

C# POST 请求到 webapi 使用控制台程序