【发布时间】:2017-08-08 15:53:59
【问题描述】:
我正在开发C# 2015 Windows 应用程序。
基本思想是从数据库中获取记录并显示到gridview。并使用RDLC 报告打印选定的网格视图记录。
有关基本概念,请参见下面的屏幕截图。
现在,我的print button 代码如下:
private void btnPrint_Click(object sender, EventArgs e)
{
List<customer> lstCustomer = new List<customer>();
foreach (DataGridViewRow row in dgCustomers.SelectedRows)
{
customer c = new customer();
c.id = Convert.ToInt32(row.Cells[dgCustomers.Columns["id"].Index].Value);
c.firstName = row.Cells[dgCustomers.Columns["first_name"].Index].Value.ToString();
c.firstName = row.Cells[dgCustomers.Columns["last_name"].Index].Value.ToString();
lstCustomer.Add(c);
}
frmReport r = new frmReport();
r.Show();
ReportViewer v = r.Controls.Find("reportViewer1", true).FirstOrDefault() as ReportViewer;
v.LocalReport.ReportEmbeddedResource = "bolt.rptBolt.rdlc";
ReportDataSource dataset = new ReportDataSource("ReportDataSet1", lstCustomer);
v.LocalReport.DataSources.Clear();
v.LocalReport.DataSources.Add(dataset);
v.LocalReport.Refresh();
v.RefreshReport();
this.Hide();
}
看,我创建了一个 List lstCustomer 类 customer 并将所选行的单元格值的对象添加到其中。
我创建了一个新表单frmReport 来显示报告,并在其中添加了reportviewer。
我还获取了一个名为rptBolt.rdlc 的Rdlc 报告并将其添加到报告查看器中。
我已经在我的列表中设置了报告的datasource。
但现在,我不确定如何将 id、名字和姓氏绑定到报告的文本框中。
附注我希望每条记录都有单独的页面。
我不知道该怎么做。有谁知道吗?
【问题讨论】:
-
也让我知道我是否做错了什么或如何处理这种不同的方式?
-
目前堆栈溢出中没有 .NET 专家可用??
-
如果我有什么问题,请告诉我任何替代方式。请问有高手吗?
-
请帮帮我.. 赏金将在 3 天后到期。