Solved

alternate row color -- ASP.net MVC4 ?

Posted on 2013-12-12
2
1,206 Views
Last Modified: 2013-12-13
How can I change the below code to alternate row color ?

Maybe something like
http://forums.asp.net/t/1810432.aspx
talks about ?
---------------------------------------------------------------------------------------------------
@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.WO)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DR)
        </td>
    </tr>
0
Comment
Question by:finance_teacher
2 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 400 total points
ID: 39715004
Here is a start which you can then change so that it fits your needs:
@{
	var rowNumber = 0;
}

@foreach (var item in Model)
{
	<tr style="background-color: @(rowNumber % 2 == 0 ? "#ff0000" : "#00ff00")">
		<td>
			@Html.DisplayFor(modelItem => item.WO)
		</td>
		<td>
			@Html.DisplayFor(modelItem => item.DR)
		</td>
	</tr>

	rowNumber++;
}

Open in new window

0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 100 total points
ID: 39716465
hi.. please try this

Take declaration of rowColor outside for statement.

@{ var rowColor = "D9E6C4"; }
@for (int i = 1; i <= 10; i++)
{
    <tr style="background-color:@rowColor;" >
        <td>
            apoorva
        </td>
    </tr>
    if (@rowColor.Equals("#ffffff"))
    {
        rowColor = "#D9E6C4";
    }
    else
    {
        rowColor = "#ffffff";
    }
}
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question