参考文章:
http://blog.csdn.net/vshirleyzhxl/article/details/6748585
环境:FastReport.Net Version 1.6.19 + VS2010 + ASPX
ASPX文件代码如下:
网上见的比较多的代码是:
protected void WebReport1_StartReport(object sender, EventArgs e)
{
FastReport.TextObject txtFoot = WebReport1.Report.FindObject("txtFoot") as FastReport.TextObject;
txtFoot.Text = "xxx"; // 我测试时失败,因为此时txtFoot等于null
WebReport1.Report.Prepare();
}
百思不得其解呀,Report.FindObject为什么获取不到txtFoot呢?
后面看了下WebReport1的属性,看到了事件一栏,恍然大悟,是不是在触发事件WebReport1_StartReport时,控件txtFoot还没准备好?
于是修改ASPX代码如下:
...
<cc1:WebReport ID="WebReport1" runat="server" Width="100%" PrintInPdf="False"
Height="100%" LocalizationFile="~/Rpt/Chinese (Simplified).frl"
onstartreport="WebReport1_StartReport" onprerender="WebReport1_PreRender" />
...
// xx.aspx.cs文件
protected void WebReport1_PreRender(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("WebReport1_PreRender");
FastReport.TextObject txtFoot = WebReport1.Report.FindObject("txtFoot") as FastReport.TextObject;
txtFoot.Text = "www";
WebReport1.Report.Prepare();
}
这下终于成功了。。。。
通过打印日志,发现WebReport事件触发顺序如下:
WebReport1_Init
WebReport1_Load
WebReport1_StartReport
WebReport1_PreRender
环境:FastReport.Net Version 1.6.19 + VS2010 + ASPX
ASPX文件代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CourseStatistical.aspx.cs" Inherits="CourseStatistical" %>
<%@ Register assembly="FastReport.Web, Version=1.6.19.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c" namespace="FastReport.Web" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:WebReport ID="WebReport1" runat="server" Width="100%" PrintInPdf="False" Height="100%" LocalizationFile="~/Rpt/Chinese (Simplified).frl" onstartreport="WebReport1_StartReport" />
</div>
</form>
</body>
</html>
网上见的比较多的代码是:
protected void WebReport1_StartReport(object sender, EventArgs e)
{
FastReport.TextObject txtFoot = WebReport1.Report.FindObject("txtFoot") as FastReport.TextObject;
txtFoot.Text = "xxx"; // 我测试时失败,因为此时txtFoot等于null
WebReport1.Report.Prepare();
}
百思不得其解呀,Report.FindObject为什么获取不到txtFoot呢?
后面看了下WebReport1的属性,看到了事件一栏,恍然大悟,是不是在触发事件WebReport1_StartReport时,控件txtFoot还没准备好?
于是修改ASPX代码如下:
...
<cc1:WebReport ID="WebReport1" runat="server" Width="100%" PrintInPdf="False"
Height="100%" LocalizationFile="~/Rpt/Chinese (Simplified).frl"
onstartreport="WebReport1_StartReport" onprerender="WebReport1_PreRender" />
...
// xx.aspx.cs文件
protected void WebReport1_PreRender(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("WebReport1_PreRender");
FastReport.TextObject txtFoot = WebReport1.Report.FindObject("txtFoot") as FastReport.TextObject;
txtFoot.Text = "www";
WebReport1.Report.Prepare();
}
这下终于成功了。。。。
通过打印日志,发现WebReport事件触发顺序如下:
WebReport1_Init
WebReport1_Load
WebReport1_StartReport
WebReport1_PreRender
WebReport1_Unload