FastReport给模板变量赋值

参考文章: http://blog.csdn.net/vshirleyzhxl/article/details/6748585
环境: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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

friendan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值