Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alternating row color MVC

I need to design a table with alternating row colors. Below is written code but its not working. May be some syntax issue for MVC. Please suggest.

@for (int i = 1; i <= 10; i++)

{

        var rowColor = "D9E6C4";
        <tr style="background-color:@rowColor;" >
            <td>apoorva</td>
        </tr>
        if (@rowColor.Equals("#ffffff"))
        {
            rowColor = "#D9E6C4";
        }
        else
        {
            rowColor = "#ffffff";
        }
}
like image 895
14578446 Avatar asked Dec 21 '11 17:12

14578446


2 Answers

CSS3 example taken from http://davidwalsh.name/css-tables-css3-alternate-row-colors

tr:nth-child(odd)    { background-color:#ffffff; }
tr:nth-child(even)    { background-color:#D9E6C4; }
like image 155
slinzerthegod Avatar answered Oct 08 '22 20:10

slinzerthegod


Try...

@for (int i = 1; i <= 10; i++)
{
    string rowColor;
    if(i % 2 == 0)
    {
        rowColor = "D9E6C4";
    }
    else
    {
        rowColor = "ffffff";
    }
    <tr style="background-color:#@rowColor;" >
        <td>apoorva</td>
    </tr>
}
like image 21
jcreamer898 Avatar answered Oct 08 '22 19:10

jcreamer898