views:

3683

answers:

7

Hi,

I want to pass some parameters to a Crystal Report like this:

ReportDocument.DataDefinition.FormulaFields[parameterName].Text   = 'Text';

This workes fine unless I want to pass a multiline textbox from ASPX (containing \n and \r chars.)

The reportviewer reports that "The matching ' for this string is missing.".

Is there any example/list/suggestion how to parse the (multiline) text and make this work?

Thanks,

Stefan

A: 

Stefan, do you really want to be able to retain the newline characters? If not I would imagine that the best approach would be to use a regex to strip them out before passing cleaned text through to your report.

ninesided
A: 

We really want to be able to retain the newline characters, e. g. for a free textfield "Message to the customer". In current sprint i simply replace all newline characters, but that's not a solution. Yust imagine what would if stackoverflow.com does not know what a newline is...

A: 

You have to replace the \r\n pair with something obscure before passing it to the report, then make a crystal formula that converts it back to cr-lf pair in the report.

Example with converting cr-lf to three underscores

C#

ReportDocument.DataDefinition.FormulaFields[somefield].Text = textWithCrLf.Replace("\r\n","___");

Crystal formula:

Replace({somefield}, "___", chr(13))

sindre j
+1  A: 

If you want to retain line breaks you should replace them with something obscure as described by sindre j. In order for the line breaks to display correctly in Crystal Reports you need to replace the obscure characters in a Crystal Report formula with html breaks. Then add your formula field to the report and right-click, select 'Format Field', select the 'Paragraph' tab, and change the 'Text Interpretation' to 'HTML Text'. You also need to make sure the 'Can Grow' attribute is checked on the 'Common' tab. See the example formula below:

"<html>" + Replace({?ParameterField}, "___", "<br>") + "<html/>"

Hope this helps.

A: 

Thanks. All done.

A: 

Regardless of your parsing technique, you may want to use the Parameter's DefaultValues or CurrentValues collections. The DefaultValues collection populates the list of available values. The CurrentValues collection populates the list of selected values.

Craig
A: 

How do I replace newlines with a formula???

oRpt.DataDefinition.FormulaFields.Item("Description").Text = "'" + Trim(Session("txtDescription")) + "'"

Richard