文件名称:reportViewer动态绑定DataTable
文件大小:84KB
文件格式:RAR
更新时间:2015-11-26 00:26:56
reportViewer DataTable 动态绑定 c# 报表
完美的数据报表reportViewer动态绑定DataTable数据, 1.创建窗体form1 2.拖入reportViewer1 3.解决方案中添加-数据-数据集(dataset1)-工具栏中拖入DataTable到xsd界面-添加列 DataColumn1-DataColumn4 4.解决方案中添加-报表-rdlc-界面添加-表-选择数据源dataset1-完成 5.form1.cs 中加入 private void button1_Click(object sender, EventArgs e) { reportViewer1.Reset(); this.reportViewer1.LocalReport.ReportEmbeddedResource = "报表test.Report1.rdlc"; reportViewer1.LocalReport.DataSources.Clear(); reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt())); this.reportViewer1.RefreshReport(); } private DataTable dt() { DataTable DataTable2 = new DataTable("dt2"); DataTable2.Columns.Add("DataColumn1", typeof(string)); DataTable2.Columns.Add("DataColumn2", typeof(string)); DataTable2.Columns.Add("DataColumn3", typeof(string)); DataTable2.Columns.Add("DataColumn4", typeof(string)); DataTable2.Columns.Add("DataColumn5", typeof(string)); for (int i = 0; i < 5; i++) { DataRow dr = DataTable2.NewRow(); dr["DataColumn1"] = "qwe1" + i.ToString(); dr["DataColumn2"] = "qwe2" + i.ToString(); dr["DataColumn3"] = "qwe3" + i.ToString(); dr["DataColumn4"] = "qwe4" + i.ToString(); dr["DataColumn5"] = "qwe5" + i.ToString(); DataTable2.Rows.Add(dr); } return DataTable2; }
【文件预览】:
报表test.suo
报表test
----DataSet1.xsd(3KB)
----bin()
--------Debug()
----Form1.Designer.cs(3KB)
----Program.cs(471B)
----报表test.csproj(5KB)
----obj()
--------x86()
----DataSet1.cs(86B)
----Form1.cs(2KB)
----app.config(117B)
----DataSet1.Designer.cs(39KB)
----Form1.resx(6KB)
----Report1.rdlc(14KB)
----DataSet1.xsc(361B)
----Properties()
--------Resources.resx(5KB)
--------Settings.settings(249B)
--------AssemblyInfo.cs(1KB)
--------Settings.Designer.cs(1KB)
--------Resources.Designer.cs(3KB)
----DataSet1.xss(3B)
报表test.sln