Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3958758
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:38:51+00:00 2026-05-20T02:38:51+00:00

I am moving my application to MVC 3 and try to use System.Web.Helpers.WebGrid. I

  • 0

I am moving my application to MVC 3 and try to use System.Web.Helpers.WebGrid. I would like to get html code like:

<table>
    <tr style="background-color: <%= item.Color %>">
    </tr>
    <tr style="background-color: <%= item.Color %>">
    </tr>
    <tr style="background-color: <%= item.Color %>">
    </tr>
</table>

There is rowStyle property, that allows to define css class for every row, but there will be different style for every row. Is it achieveable easily?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:38:51+00:00Added an answer on May 20, 2026 at 2:38 am

    So I had to finish with hack. First, include color as a part of another column. It had to be returned as MvcHtmlString to avoid additional encoding:

    <%  
        var grid = new WebGrid(Model);
    %>
    <%= 
        grid.GetHtml(
            tableStyle: "table_class",
            columns:  grid.Columns(
                grid.Column("Importance", CTRes.Importance, (item) => 
                    new MvcHtmlString(Html.Encode(item.Importance) + 
                    "<div class='color' style='display: none;'>#" + item.Color + "</div>"))
            )
        ) 
    %>
    

    Then we are setting bacground color in $(document).ready():

    <script type="text/javascript">
        $(document).ready(
            function () {
                $('.table_class .color').each(function (index, element) { $(element).parent().parent().css('background-color', $(element).html()); });
            }
        );
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm moving an application to use the Spring3 framework and I have code that
I have recently designed a web application that I would like to write in
I need to make a web application and I want to use MVC. However,
I have a simple C# Console application in which I use FileSystemWatcher and Moving
I'm in the process of moving a large classic ASP application to ASP.NET MVC
I have some static (pure html) pages in my MVC application that I need
I'm trying to molularize my ASP.NET MVC application by moving each Area into their
I am expanding/converting a legacy Web Forms application into a totally new MVC application.
I have made my application in ASP.NET MVC 3. The server I use only
We are beginning the process of moving from Web Forms to MVC for all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.