Script syntax error
Hi!
So, what am I trying to achieve: I would like a TextBox to display different text according to the value assigned to it. When I design the report, the TextBox, lets call it Text1 holds the string "[DataTable.Data]" because it will be populated in realtime from code. I would like it to print, for example "FOO" when the data is "1" and "BAR" when the data is "2". Kinda like the highlight expresion option but with actual text change.
I tried a Text1.AfterPrint event, something like:
So, what am I trying to achieve: I would like a TextBox to display different text according to the value assigned to it. When I design the report, the TextBox, lets call it Text1 holds the string "[DataTable.Data]" because it will be populated in realtime from code. I would like it to print, for example "FOO" when the data is "1" and "BAR" when the data is "2". Kinda like the highlight expresion option but with actual text change.
I tried a Text1.AfterPrint event, something like:
private void Text1_AfterPrint(object sender, EventArgs e){
  Text1.Text == "1" ? Text1.Text = "FOO" : Text1.Text = "BAR";
}
But all I got in response was:
5.6.2009 14:49:07 (21,36): error CS1525: Invalid expression term '?'
(21,38): error CS1002:; expected
(21,68): error CS1002:; expected
(21,75): error CS1525: Invalid expression term ':'
(21,77): error CS1002:; expected
(21,109): error CS1002:; expected
Any ideas as to why this doesnt work?
Comments
Text1.AfterPrint is not a good place for this - the object is printed already, all changes in its state will be ignored. Better to use the band.AfterLayout - all objects are filled with data and ready to print.
The correct code would be:
But I want to suggest you more elegant solution: just put the following text in your Text object:
[[DataTable.Data] == "1" ? "FOO" : "BAR"]
In this case, you don't need the script at all.
[[DataTable.Data] == 1 ? "FOO" : "BAR"]