Solved

alternate row color -- ASP.net MVC4 ?

Posted on 2013-12-12
2
1,213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TCP Chat/GPS application security thru firewall 4 55
C# LINQ query question 11 32
Datagridview column resizing 8 28
Click print button programmatically on print showdialog 1 24
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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