2011-09-22 50 views
2

首先讓我告訴你一件事,我從來沒有與任何類型的報告合作過。我已閱讀有關此主題的所有相關問題和答案。但找不到具體的解決辦法。如何在Crystal或rdlc報告中綁定c#的業務對象?

我的問題是我有一個非常簡單的報告,使我必須從數據庫的視圖中顯示一行。爲了獲得該行,我創建了一個業務對象(實體)。該實體完美地保存了我的行。我也嘗試過水晶報告和rdlc報告。但最終我只會選擇一個。所以我的解決方案中有一份水晶報告。在我的aspx表格中,我使用了一個報表查看器。但我不知道如何使這三件事情一起工作,即報告,報告查看器和持有該信息的對象或實體。

現在的代碼放在這裏

晶體報告的名稱是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; 
    } 
} 

請給我一個解決方案,我迫切需要解決方案。提前感謝所有智能科技愛好者。

回答

1

您必須創建一個ReportSource對象並將其指定給您的報告,如here所述。

CrystalReportViewerMRN.ReportSource = myReportSource;