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

  • Home
  • SEARCH
  • 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 891245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:51:32+00:00 2026-05-15T13:51:32+00:00

Okay I clearly haven’t fed google the right query or I would’ve found out

  • 0

Okay I clearly haven’t fed google the right query or I would’ve found out by now. I’m hoping someone on this forum can help me.

So I have a datatable that I’m adding rows to based on a datareader that’s getting its info from an sql query executed over a database. So far, so good. Now, one of those columns is called ‘analysis’, and I need its background color to be green if the preceding two columns are matched, and red otherwise.

If I can’t touch the background color, I’d like to insert a special character, any javascript that isn’t interpreted as text.

Simply put, I’d like css control over a gridview from codebehind. I’ve looked and looked to no avail. I found this guy, but I haven’t checked if his solution works on an ASP.Net/C# website. Any ideas?

  • 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-15T13:51:32+00:00Added an answer on May 15, 2026 at 1:51 pm

    In the GridView_RowDataBound event, get the cell you want to change the back-color, set the color of the cell if your condition is tested true.

    /// <summary>
    /// Handles gridview row data bound event.
    /// </summary>
    /// <param name="sender">Sender Object</param>
    /// <param name="e">Event Argument</param>
    protected void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // We don’t want to apply this to headers.
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            try
            {
                //your data-object that is rendered in this row, if at all required.
                //Object obj = e.Row.DataItem;
    
                //find the right color from condition
                string color = condition ? "#ff9900" : "some-other-color";
    
                //set the backcolor of the cell based on the condition
                e.Row.Cells[4].Attributes.Add("Style", "background-color: " + color + ";");
            }
            catch
            {
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay the previous question was answered clearly, but i found out another problem. What
Okay, this should be an easy one for the pros out there (disclaimer, I'm
Okay, so I'm making a table right now for Box Items. Now, a Box
Okay, this has been absolutely infuriating to debug, I have finally figured out what
Okay I edit my question, try to explain it more clearly: I have a
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess
Okay, this is probably a very basic question; but, I'm just getting back in
Okay - I'm not even sure that the term is right - and I'm

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.