But I have 15 lines of code from Fac1Raw to Fac15Raw, could I not do it inline html if @aaa=1 then <span color=red> else if @aaa=2 then <span color=green> else @aaa=3 <span color=black> ?
But I have 15 lines of code from Fac1Raw to Fac15Raw, could I not do it inline html if @aaa=1 then <span color=red> else if @aaa=2 then <span color=green> else @aaa=3 <span color=black> ?
would this work or not?
Yes it would work. But it would be difficult to maintain and would not be reusable in other places. But there's nothing to stop you adding it inline if you want.
happysack
Member
18 Points
46 Posts
code as varialable in IF statement? Easy Q?
Nov 20, 2012 05:30 PM|LINK
So i have an if statement..
currently works to return a result variable such as
result = result1
else if a=b
result = result2
my question is i want the result to be a different colour based the result
I tried to add code to the result is the way to do it?
such as
Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: code as varialable in IF statement? Easy Q?
Nov 20, 2012 06:34 PM|LINK
Make the colour the variable:
var result = "red"; if(some_condition){ result = "green"; } <span style="color: @result">result 1</span>Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
happysack
Member
18 Points
46 Posts
Re: code as varialable in IF statement? Easy Q?
Nov 20, 2012 09:41 PM|LINK
This is loaded into function so i need to needs to be in a single result. I am using this function against multiple things.
hopes this makes sense.
Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: code as varialable in IF statement? Easy Q?
Nov 21, 2012 04:40 AM|LINK
Use @functions to house your code: http://www.mikesdotnetting.com/Article/173/The-Difference-Between-@Helpers-and-@Functions-In-WebMatrix
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
ayanmesut
Member
219 Points
85 Posts
Re: code as varialable in IF statement? Easy Q?
Nov 21, 2012 07:48 AM|LINK
your code:
if (a>b){ result = result1; col = "red"; } else if (a=b){ result = result2; col = "green"; }When you show it on the page:
happysack
Member
18 Points
46 Posts
Re: code as varialable in IF statement? Easy Q?
Nov 21, 2012 05:52 PM|LINK
But I have 15 lines of code from Fac1Raw to Fac15Raw, could I not do it inline html if @aaa=1 then <span color=red> else if @aaa=2 then <span color=green> else @aaa=3 <span color=black> ?
would this work or not?
ayanmesut
Member
219 Points
85 Posts
Re: code as varialable in IF statement? Easy Q?
Nov 22, 2012 06:03 AM|LINK
you can create an array of 15 colors and use it
string[] colors= new string[]{ “red”, “green”, “blue”,...};Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: code as varialable in IF statement? Easy Q?
Nov 22, 2012 06:56 AM|LINK
Yes it would work. But it would be difficult to maintain and would not be reusable in other places. But there's nothing to stop you adding it inline if you want.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
ashoksudani
Participant
1043 Points
213 Posts
Re: code as varialable in IF statement? Easy Q?
Nov 23, 2012 12:02 PM|LINK
if your Result is Fix like Red,Green,Blue, Yello, Etc then you can Create Css Class AS per Result and Color.
so like you want Color Red when Result is Green then
css like this
#Green{Color:Red}
#Red{Color:Green}
result = "<span Class=@Result1>result 1</span>";
happysack
Member
18 Points
46 Posts
Re: code as varialable in IF statement? Easy Q?
Nov 23, 2012 02:31 PM|LINK
all very helpful answers.
ashoksudani had the best solution for me personally.