Solved

alternate row color -- ASP.net MVC4 ?

Posted on 2013-12-12
2
1,186 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now