- public partial class _Default : System.Web.UI.Page
- {
- //页面加载的时候绑定数据源
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- FillDataToReport();
- }
- }
- public void FillDataToReport()
- {
- DataTable dt = new DataTable(); //创建一个datatable
- dt.Columns.Add("studentID", typeof(int));
- dt.Columns.Add("studentName", typeof(string));
- dt.Columns.Add("password", typeof(string));
- dt.Rows.Add(1, "王伯仙", "001");
- dt.Rows.Add(2, "白云飘飘", "002");
- dt.Rows.Add(3, "小神仙", "003");
- this.ReportViewer1.LocalReport.ReportPath = "student.rdlc"; //查找要绑定的报表
- this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("T_Student", dt)); //绑定数据源
- }
- }
时间: 2024-11-10 01:32:48