Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#2015-Gridview选定行到RDLC报告-每页一行_C#_C# 4.0_Rdlc - Fatal编程技术网

C#2015-Gridview选定行到RDLC报告-每页一行

C#2015-Gridview选定行到RDLC报告-每页一行,c#,c#-4.0,rdlc,C#,C# 4.0,Rdlc,我正在开发C#2015windows应用程序 基本思想是从数据库中获取记录并显示在gridview中。并使用RDLCreport打印网格视图的选定记录 请参见下面的屏幕截图了解基本想法 现在,我的打印按钮代码如下: private void btnPrint_Click(object sender, EventArgs e) { List<customer> lstCustomer = new List<customer>(); foreach (Da

我正在开发
C#2015
windows应用程序

基本思想是从数据库中获取记录并显示在gridview中。并使用
RDLC
report打印网格视图的选定记录

请参见下面的屏幕截图了解基本想法

现在,我的
打印按钮
代码如下:

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();
}
private void btnPrint\u单击(对象发送者,事件参数e)
{
List lstCustomer=新列表();
foreach(dgCustomers.SelectedRows中的DataGridViewRow行)
{
客户c=新客户();
c、 id=Convert.ToInt32(行.Cells[dgcusters.Columns[“id”].Index].Value);
c、 firstName=row.Cells[dgcusters.Columns[“first_name”].Index].Value.ToString();
c、 firstName=row.Cells[dgcusters.Columns[“last_name”].Index].Value.ToString();
添加(c);
}
frmReport r=新的frmReport();
r、 Show();
ReportViewer v=r.Controls.Find(“reportViewer1”,true).FirstOrDefault()作为ReportViewer;
v、 LocalReport.ReportEmbeddedResource=“bolt.rptBolt.rdlc”;
ReportDataSource数据集=新的ReportDataSource(“ReportDataSet1”,LSTCOUSTOMER);
v、 LocalReport.DataSources.Clear();
v、 LocalReport.DataSources.Add(数据集);
v、 LocalReport.Refresh();
v、 刷新报告();
this.Hide();
}
请参见,我已经创建了类
customer
列表lstCustomer
,并在其中添加了所选行单元格值的对象

我创建了一个新表单
frmReport
来显示报告,并在其中添加了一个
reportviewer

我还获取了名为
rptBolt.Rdlc
Rdlc
报告,并将其添加到报告查看器中

我已经用我的列表设置了报告的
数据源

但现在,我不知道如何将id、名字和姓氏绑定到报告的文本框中

p.S.我希望每个记录有单独的页面。

我不知道怎么做。有人知道吗?

你可以这样做, 在frmReport中,创建一个名为
ReportId
的属性,并按如下方式使用

/* Below Code goes to frmReport.cs */
//after the frmReport()
public int ReportId;

//In your forms where u have rdlc
frmReport r = new frmReport();
r.ReportId = GetTheSelectedRecordFromGridView();
r.Show();

ReportViewer v = r.Controls.Find("reportViewer1", true).FirstOrDefault() as ReportViewer;
v.LocalReport.ReportEmbeddedResource = "bolt.rptBolt.rdlc";
//Apply your ReportId to filter the record
//But it is good, to apply this filter to the original database call/query
lstCustomer = lstCustomer.Where(x=>x.Id==ReportId).ToList();
ReportDataSource dataset = new ReportDataSource("ReportDataSet1", lstCustomer);
v.LocalReport.DataSources.Clear();
v.LocalReport.DataSources.Add(dataset);
v.LocalReport.Refresh();
v.RefreshReport();
this.Hide();

private int GetTheSelectedRecordFromGridView()
{
 //Write your logic, to get the selected Id;
}
将reportId传递给frmReport,从数据库中筛选记录,使用所需字段构建报告数据集,使用reportviewer绑定并显示id、firstname和lastname字段


希望您了解逻辑/想法。

我想在报告的文本框中显示id。如果我在
rptBolt.rdlc
中的文本框中设置
id
名字
姓氏
字段,会怎么样。每个记录将有一个新的页面,我将很容易打印它们。如何实现这一点?是的,我可以理解,但我需要在报告文本框中设置哪些属性来显示id,名字和姓氏,以及我需要做什么样的设置才能每页显示一条记录?ReportViewer可以从您的报表数据集中获取数据。另外,请告知我是否有任何错误,或者如何以不同的方式处理此问题?目前没有.NET专家在stack overflow中工作??如果我有以下问题,请告诉我其他方法有点不对劲。有专家吗?请帮帮我。。赏金将在3天后到期。