Solved

alternate row color -- ASP.net MVC4 ?

Posted on 2013-12-12
2
1,202 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cant save 3D 4 19
VB.NET - Error - Object not set in Module 4 33
Database Connections Not being returned to Connection Pool 7 25
ASP.NET MVC -Add authentication 2 21
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

772 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