Solved

If condition in the string builder.

Posted on 2007-04-02
3
423 Views
Last Modified: 2008-01-09
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
Comment
Question by:rowmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Expert Comment

by:dstanley9
ID: 18836502
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
 

Author Comment

by:rowmark
ID: 18836760
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
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 18836796
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question