【学习笔记】FastReport控件

1.FastReportUserControl控件继承FastReport控件

加载页面设置打印模版地址

代码如下(示例):

this.fastReportUserControl.PrintTemplateFile = "./template/模版.frx";

        /// <summary>
        /// 设置菜单按钮只读性
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSelectedDataChanged(SelectedDataChangedEventArgs e)
        {
            base.OnSelectedDataChanged(e);
            if (this.TabContext != null && this.HasSelectedRow == true)
            {
                //获取选择行的ID
                int id= (int)this.GetSelectedXEntity<XEntity>(typeof(XEntity)).Id;
                using (DBClient client = new DBClient())
                {
                    DataTable dt;
                    string errorText = string.Empty;
                    //过滤条件
                    string filter = string.Format("T.ID={0}", surveyRecordId);
                    if (client.ExecuteQuery("dbo.TABLE", new Dictionary<string, object>() { { Common.COL_FILTER, filter } }, true, false, "", out dt, out errorText) == true)
                    {
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            //装载模板,显示报表
                            Dictionary<string, DataTable> UserDataTableList = new Dictionary<string, DataTable>(){ { "行数据", dt } };
                            this.fastReportUserControl.UserDataTableList = UserDataTableList;
                            this.fastReportUserControl.ShowPrintData();
                        }
                    }
                }
            }
        }

2.注意

1、模版中绑定的数据源字段为数据库字段,中文别名显示不出

2、安装FRNetDemo


版权声明:本文为qq_41376300原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。