Solved

alternate row color -- ASP.net MVC4 ?

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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