Vs2010中rdlc报表绑定DataTable数据源

首先,新建一个网站,接着添加数据集,并且命名为student,如下图所示:

     

 

          在该数据集对象上面添加datatable,并且设置列名,如下图所示:

        添加一张报表,命名为student,如下图所示:

         向报表中添加“表”这一项,如下图所示:

 

        这时就弹出一个选择数据源的对话框,如下图所示,自己选择要添加的数据源并命名:

        将对应的datatable项添加到表中,如下图所示:

 

        创建一个aspx页面,拖动reportviewer控件到页面上面,并拖动scriptmanager控件,接下来是简单的代码编写过程:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 using System.Data;
 8 using Microsoft.Reporting.WebForms;
 9 
10 public partial class _Default : System.Web.UI.Page
11 {
12     //页面加载的时候绑定数据源
13     protected void Page_Load(object sender, EventArgs e)
14     {
15         if (!IsPostBack)
16         {
17             FillDataToReport();
18         }
19     }
20 
21     public void FillDataToReport()
22     {
23 
24         DataTable dt = new DataTable();         //创建一个datatable
25         dt.Columns.Add("studentID", typeof(int));
26         dt.Columns.Add("studentName", typeof(string));
27         dt.Columns.Add("password", typeof(string));
28         dt.Rows.Add(1, "王伯仙", "001");
29         dt.Rows.Add(2, "白云飘飘", "002");
30         dt.Rows.Add(3, "小神仙", "003");
31 
32         this.ReportViewer1.LocalReport.ReportPath = "student.rdlc";  //查找要绑定的报表
33         this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("T_Student", dt));  //绑定数据源
34 
35     }
36 }

页面运行之后是这样的:

 

转载于:https://www.cnblogs.com/zzzzw/p/4447194.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值