如何在水晶或 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;
}
}
,请给我一个解决方案,我非常需要解决方案。提前感谢所有聪明的技术极客。
First let me tell you one thing, I have never worked with any sort of reporting yet. I have read all the related question and answer on this topic. But could not find any concrete solution.
My problem is I have a very simple report to make where I have to show a row from a view from the database. In order to have that row, I have created a business object (entity). that entity is holding my row perfectly. I have tried crystal report and rdlc report as well. But at the end I will choose only one. So I have a crystal report in my solution. In my aspx form I have taken a report-viewer. but I don know how to make these three things work together, i.e. the report, the report viewer and the object or entity that is holding the information.
Now the code goes here
the name of the crystal report is FormSaleMoneyReceipt.rpt
my aspx page is
<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>
My code behind file is
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;
}
}
please, please give me a solution, I am desperately in need of the solution. Thank you all the smart tech geeks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须创建一个
ReportSource
对象并将其分配给您的报表,如 此处。CrystalReportViewerMRN.ReportSource = myReportSource;
You have to create a
ReportSource
object and assign that to your report, as described here.CrystalReportViewerMRN.ReportSource = myReportSource;