14 January 2008

Crystal Report : Programmatically set Text of Label

A simple(?) line changes the text of a label (TextObject in Crystal Report):

((TextObject)rptDoc.ReportDefinition.ReportObjects["myTextObject"]).Text = "Here is my text.";

Here "myTextObject" is the name of the TextObject used in the report. To set the ObjectName, right click on the object >> format object >> object name.

Sample Code:

string reportPatfh = "CrystalReport1.rpt";

ReportDocument rptDoc = new ReportDocument();

rptDoc.Load(reportPatfh); ((TextObject)rptDoc.ReportDefinition.ReportObjects["myTextObject"]).Text = "Here is my text.";

crystalReportViewer1.ReportSource = rptDoc;

There is another way:

((TextObject)rptDoc.ReportDefinition.Sections[2].ReportObjects["myTextObject"]).Text = "Here Is My Text";

But i'm surprised to see that SectionIndex does not have any effect i.e. whatever the index is (1, 2 3 0r 4 ), the result is same. Can anybody explain this?


Anamika said...
This comment has been removed by the author.
Anamika said...

Thanks Yar. Since a long time i found solution of my query.
i knew that in vb 6 there is a function "settext" but i couldnt found same function in .net..

but u make my day..

Thanks Again.

আলোর ছটা said...

@Anamika: my pleasure :)


© 2007 t!ps n tr!cks: Crystal Report : Programmatically set Text of Label

Template unik dari rohman

---[[ Skip to top ]]---