Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 3 option to change the color of label

1 - Red
2 - Green
3 - yallow

I created 100 labels.
I have table contains the name of the lable and the value of option

NAME OF LABLE OPTION
A1 1 ---> Red
A2 2 ---> Green
A3 1 ---> Red
A4 3
A8 1
B1 1
B3 2

How can I change the colors of labels?
Posted
Comments
[no name] 11-Sep-15 2:48am    
Do you want do it through javascript or in C#? Secondly please tell us how you are holding that data?
Member 11232188 11-Sep-15 10:40am    
I will try to use C#.
I will hold the data when the user request the page
Sergey Alexandrovich Kryukov 11-Sep-15 2:59am    
What have you tried so far?
—SA
j snooze 11-Sep-15 12:55pm    
why don't you just add a class name column to the table that matches your css class names signifying a red/yellow/green color?
Member 11232188 11-Sep-15 14:50pm    
How??

1 solution

1. Create classes for red,green and yellow which makes label color red.

2. Include this value(1 for Red,2 for Green etc) in Model object and in View check the condition and change the class

C#
<label class="@if(@Model.option==1)" classred=" else if(@Model.option==2)" classgreen=" else(@Model.option==3)" classyellow="">text</label>


Hope this will help you
 
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