Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I would like to change the color in the (td) field [change color - change / transfer to a different css class?]

Condition:
The condition comes from the "if" query. if (sb == true) then nothing changes, if (sb == false) "[else]"
then the css class in (td class="InputsForUserColor1") may change to class="InputsForUserColor1Change".


I note
(td class="InputsForUserColor2") is unchanged



Code html (razor/C#):
the variable "sb" is outside "if", assumes a different value

HTML
@for (int sth = 0; sth< ViewBag.sth; sth++)
{
                if (sb == true){
                    varSth = "00:00";
                }
                else{
                   varSth = "20:00";
                }
                         @for (int sthElse = 0; sthElse< ViewBag.sthElse; sthElse++)
                          {
                                if (nr_columns == 2){
                                    <td id="td01" class="InputsForUserColor1"></td>
                                }
                                if (nr_columns == 3){
                                    <td id="td01" class="InputsForUserColor2"></td>
                                }
                          }
}



CSS:
CSS
.InputsForUserColor1, area {
    background-color: papayawhip;
    border: hidden;
    align-content: center;
    align-items: center;
    vertical-align: central;
}

.InputsForUserColor1Change, area {
    background-color: white;
    border: hidden;
    align-content: center;
    align-items: center;
    vertical-align: central;
}



personally I didn't write it because I don't know how to approach it

What I have tried:

personally I didn't write it because I don't know how to approach it
Posted
Updated 3-Feb-20 4:41am

Changing a CSS class in a Razor view is simple:
Razor
@{
    string cssClass = sb ? "InputsForUserColor1" : "InputsForUserColor1Change";
}

...

<td id="td01" class="@cssClass"></td>
Razor syntax reference for ASP.NET Core | Microsoft Docs[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900