ICreated a Webgrid on MVC, I have around 22 Columns returned by the Webgrid, I am trying to generate Background color Red, Green, Yellow depending on the Condition.
1 --> Green
0 --> Red
-1 --> Yellow
I have a Query but it is not working as expected, I need to put each column number that way I need to create 22 conditions but i need something simple which says if its 1 then Green, 0 Red and -1 Yellow.
Please help, as i couldnt find the answer anywhere, I am trying for this for a while.
Mobeen RashidPosted Jun 27, 2017, 2:53 AM
Megna MusapetaPosted Jun 27, 2017, 2:30 AM
Hello Mobeen, thanks for the Link its really helped me to understand but as i am really new to MVC, can you Please help me this is taking too much of time fo rme to understand :(
.bg-color-green {
background-color: green;
}
.bg-color-yellow {
background-color: yellow;
}
.bg-color-red {
background-color: red;
}
{ "red"} else if(-1)
{ "yellow"} else{"default color"}
)">
Mobeen RashidPosted Jun 24, 2017, 3:11 AM
Megna MusapetaPosted Jun 23, 2017, 7:23 PM
Thanks, Mobeen for your Reply but i am new to MVC, can you please elaborate on how to write the Razor view.
background-color: green;
}
.bg-color-yellow {
background-color: yellow;
}
.bg-color-red {
background-color: red;
}
{ "red"} else if(condition==-1)
{ "yellow"} else{"default color"}
)">
Mobeen RashidPosted Jun 23, 2017, 3:24 AM
Megna MusapetaPosted Jun 23, 2017, 2:36 AM
Thanks Sundar for your Reply but I have around 22 Columns, If i write it this way i need to create 22 each function conditions, I need something which is simple to identify if its
$('#gridMapping > tbody > tr').each(function (index) {
if ($(this).children('td:nth-child(5)').text() == 1) {
$(this).children('td:nth-child(5)').css("background-color", "green");
}
else if ($(this).children('td:nth-child(5)').text() == 0) {
$(this).children('td:nth-child(5)').css("background-color", "red");
}
else {
$(this).children('td:nth-child(5)').css("background-color", "Yellow");
}
});
Manikandan MurugesanPosted Jun 17, 2017, 1:55 PM
css will be
body
{
background-color : black ;
First, I don't think you can use that particular CSS selector (I think it translates to select element with ID="body" and also ID="Login" (or "Geldi"), but CSS is not my strength). If you are setting it for the body tag of the page, get rid of the
#bodyand just usebodysince you can select by HTML element name. So instead:body#Loginandbody#GeldiAfter that, it would probably be best to use ViewData, and set it in your subview (Login view or something), which will then make it available to your Master View
For instance:
_Layout.cshtml
Login.cshtml
Sundaram SubramanianPosted Jun 17, 2017, 3:54 AM