简体   繁体   English

如何在运行时设置水晶报表的文本框值?

[英]How to set crystal report's textbox value at run time?

How to set crystal report's textbox value at run time. 如何在运行时设置crystal report的文本框值。 I have a textbox in section2 (page header) in crystal report, now I have to set Text property of this textbox at run time. 我在crystal report中的section2(页眉)中有一个文本框,现在我必须在运行时设置此文本框的Text属性。 Basically I have to pass user name in this textbox. 基本上我必须在此文本框中传递用户名。

You can change textbox text in runtime. 您可以在运行时更改文本框文本。 You can use this: 你可以用这个:

using CrystalDecisions.CrystalReports.Engine;

rptMyReport report = new rptMyReport();
TextObject to = (TextObject)report.ReportDefinition.Sections["Section2"].ReportObjects["textboxname"];
to.Text = newvalue;

The another way is to use parameters. 另一种方法是使用参数。

If you have the user name before the report opens you can add a parameter field (string) to the report and then put that field on the report where you want it to appear at runtime. 如果在报表打开之前有用户名,则可以在报表中添加参数字段(字符串),然后将该字段放在报表中,以便在运行时显示该字段。 You will just need to pass it into the report as a parameter just like you would any other parameter. 您只需将其作为参数传递到报告中,就像您将任何其他参数一样。

    Dim UserName As String = "BukHix" 
    crDOC.SetParameterValue("UserName", UserName)

尝试这个

((TextObject)rpt.Section2.ReportObjects["Textbox"]).Text = "yourvalue";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM