[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

gridview cell color, c#

The existing code below, applies conditional format on a gridview (works fine). It applies shades to the entire row when it meets the criteria. This gridview has 3 columns in a row.

Question: How can I modify this code so that it will apply conditional format only to the last cell in a row?

Thank you.
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.CssClass = "highlightBracketground";
            var val = e.Row.Cells[2].Text;
            var snglVal = Single.Parse(val);
            e.Row.CssClass = snglVal > 0.0 ? "highlightBracketground" : "bracketground";
        }

Open in new window

0
Mike Eghtebas
Asked:
Mike Eghtebas
1 Solution
 
Robert SchuttSoftware EngineerCommented:
Try this:
e.Row.Cells[e.Row.Cells.Count - 1].CssClass = snglVal > 0.0 ? "highlightBracketground" : "bracketground";

Open in new window

Note of course the class will not show if your css contains "tr.highlightBracketground { ... }", either define the same class for td or leave out tr so it's used for any element with that class.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Excellent, like always.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now