• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

If condition in the string builder.

Hello Experts,

I am building XML string to create a RDL file> Below is a piece of code from the same.
                writer.WriteStartElement("Style");
               writer.WriteElementString("TextDecoration", "Underline");
               writer.WriteElementString("FontWeight", "700");
               writer.WriteElementString("FontSize", "9pt");
               writer.WriteElementString("Color", "DarkSlateBlue");
               
               writer.WriteEndElement(); // Style

Currently the Color is hadcoded as DarkSlateBlue.
I need to write a condition for the color as shown as below
Iif(RowNumber("OrderDetail") Mod 2, "White", "AliceBlue")
How do I do this in the writer.WriteElementString("Color", "DarkSlateBlue"); something like this

0
rowmark
Asked:
rowmark
  • 2
1 Solution
 
dstanley9Commented:
Are you using C# or VB?

C#:
writer.WriteElementString("Color", RowNumber("OrderDetail") % 2 == 1 ? "White" : "AliceBlue");

VB.NET:
writer.WriteElementString("Color", Iif(RowNumber("OrderDetail") Mod 2 = 1, "White", "AliceBlue"));
0
 
rowmarkAuthor Commented:
I am getting an error saying RowNumber cannot exist in the current context and
Error      1      Unexpected character sequence. Expected a property name for the "<property> : <value>" declaration.      

How do I build a string that will return exactly like the one shown below:
=Iif(RowNumber("Table1") Mod 2, "White", "AliceBlue")

writer.WriteElementString("BackgroundColor", "=Iif(RowNumber('Table1') Mod 2, 'White', 'AliceBlue')");

Instead of single quote for Table1 and White and AliceBlue if we make them double quotes it will work.

Pls help
0
 
dstanley9Commented:
OK I'm with you now.  In C# you need to escape the double quotes:

writer.WriteElementString("BackgroundColor", "=Iif(RowNumber(\"Table1\") Mod 2, \"'White\", \"'AliceBlue\")");

In VB, do the same thing woth two double quotes ("") instead of slash-quote.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now