多语言展示
当前在线:539今日阅读:31今日分享:25

使用FastReport.Net的RegisterData注册DataSet

FastReport在打印报表、excel等方面功能特别强大,本文讲解一个简单的例子,使用FastReport.Net的RegisterData注册DataSet对象。在Asp.Net中使用FastReport,必须要先安装FastReport.Net,安装的时候VS2010要关闭。
方法/步骤
1

打开FastReport的设计器,选择【File】-》【New】 新建FastReport模板,选择下图的1。

2

选择【View】-》【Data】,显示如下,导出Dictionary,保存。

3

编辑导出的.frd文件,编辑完后保存,再导入。(1)  TableDataSource 是数据源节点。(2)  Name是DataSet对象的Table的表名。(3)  Column是Table的列,模板绑定数据时,使用Column的Name属性。如下:           

4

编辑模板,添加一个Table控件。第一行直接双击输入文本;第二行直接将右边的数据源托到单元格中;设置边框、字体。

6

添加c#代码新建一个测试页面test.aspx,将一个FastReport控件拖放到页面上(只有按照过FastReport.net,且引用了FastReport.dll,FastReport.Bars.dll,FastReport.Web.dll之后才可以) 添加后页面如下:    

               后台方法:        protected void WebReport_StartReport(object sender, EventArgs e)        {             DataSet ds = new DataSet();             DataTable table1 = new DataTable();            table1.TableName = 'Table1'; // 一定要设置表名称            ds.Tables.Add(table1);            // 添加表中的列            table1.Columns.Add('姓名', typeof(string));            table1.Columns.Add('密码', typeof(string));            // 任意添加一些数据            for (int i = 0, maxI = 10; i < maxI; i++)            {                DataRow row = table1.NewRow();                row['姓名'] = '我是' + i.ToString();                row['密码'] = i.ToString();                table1.Rows.Add(row);            }                       Report FReport = (sender as WebReport).Report;                   string sPath = GetReportsPath('test.frx') ;            FReport.Load(sPath);            // 将DataSet对象注册到FastReport控件中            FReport.RegisterData(ds);         }         ///         /// 获取fastreport模板的路径        ///         /// 模板名称        /// 返回模板路径        public string GetReportsPath(string sReportName)        {            return FastReport.Utils.Config.ApplicationFolder + 'Reports\\' + sReportName;        }

7

测试效果1对应保存,可以是各种格式;2对应打印;3对应分页。

推荐信息