WinForm rdlc 报表自定义datatable数据源

  1. public partial class _Default : System.Web.UI.Page  
  2. {  
  3.     //页面加载的时候绑定数据源  
  4.     protected void Page_Load(object sender, EventArgs e)  
  5.     {  
  6.         if (!IsPostBack)  
  7.         {  
  8.             FillDataToReport();  
  9.         }  
  10.     }  
  11.   
  12.     public void FillDataToReport()  
  13.     {  
  14.   
  15.         DataTable dt = new DataTable();         //创建一个datatable  
  16.         dt.Columns.Add("studentID", typeof(int));  
  17.         dt.Columns.Add("studentName", typeof(string));  
  18.         dt.Columns.Add("password", typeof(string));  
  19.         dt.Rows.Add(1, "王伯仙", "001");  
  20.         dt.Rows.Add(2, "白云飘飘", "002");  
  21.         dt.Rows.Add(3, "小神仙", "003");  
  22.   
  23.         this.ReportViewer1.LocalReport.ReportPath = "student.rdlc";  //查找要绑定的报表  
  24.         this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("T_Student", dt));  //绑定数据源  
  25.   
  26.     }  
  27. }  
posted @ 2015-06-19 16:42  西西M  阅读(1559)  评论(0编辑  收藏  举报