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 8656401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:15:59+00:00 2026-06-12T15:15:59+00:00

I am databinding a gridview and one of the columns is defined as shown

  • 0

I am databinding a gridview and one of the columns is defined as shown below. What I would like to do is to colour the text depending on whether the text says “Yes” or “No”. If the text is “Yes” I’d like to set it to red else set it to green. Can this be done and if so should it be done via css or can I add some code to the line?

<asp:TemplateField HeaderText="Validated" ItemStyle-HorizontalAlign="Center" SortExpression="Product">
    <ItemTemplate>
        <asp:Label ID="lblValidated" runat="server" Text='<%# Bind("Validation") %>' />
    </ItemTemplate>
</asp:TemplateField>
  • 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-06-12T15:16:00+00:00Added an answer on June 12, 2026 at 3:16 pm

    The below should do what you want.

    ASP.NET

    <asp:TemplateField HeaderText="Validated" ItemStyle-HorizontalAlign="Center" SortExpression="Product">
    <ItemTemplate>
        <asp:Label ID="lblValidated" runat="server" Text='<%# Bind("Validation") %>' CssClass='<%# SetColor(DataBinder.Eval(Container.DataItem, "Validation")) %>'  />
    </ItemTemplate>
    

    C#

    public string SetColor(string Text)
    {
        return Text.ToUpper == "YES" ? "GreenClass" : "RedClass"
    }
    

    CSS

    .GreenClass{color:green;}
    .RedClass{color:red;}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project where I'm databinding a gridview to a list, where one
how would i change the value IBM to something arbitrary like Cisco in one
When databinding to an ASP .NET GridView, how does one change the background color,
I am databinding a GridView to an object datasource. The gridview contains a TemplateField
When doing databinding does one have to implement INotifyPropertyChanged on the datacontext in WPF?
I'm using a gridview to display and access a sql database and using databinding.
We have an app that uses simple one way binding with a GridView to
I need some help in rendering a dynamic gridview. Using the source code below,
I am databinding my gridview in VB code behind. Because of this I know
I have a simple GridView ; something like this for a regular Item or

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.