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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:08:13+00:00 2026-05-11T07:08:13+00:00

When databinding to an ASP .NET GridView, how does one change the background color,

  • 0

When databinding to an ASP .NET GridView, how does one change the background color, based on a boolean value that is a column in the data table that the GridView is bound?

For instance if you are bound to a table that has two columns: Name, LikesBurritos. And you want to have the labels of people’s names be Blue if they like burritos and white if they don’t.

Iterating through the data table or list of objects defeats the purpose of databinding… And there are lots of places we use databinding for the express point of not coding the add of every column while iterating through the set. I’m curious if you can do this declaritivly by using an expresion in the markup…

  • 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. 2026-05-11T07:08:14+00:00Added an answer on May 11, 2026 at 7:08 am

    Use the RowDataBound event built into the GridView, then you could do something like this (in VB.NET):

    Private Sub FormatGridView(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _         Handles gvBurritoPeople.RowDataBound    Dim drBurritoPeople As BurritoPeopleRow    If e.Row.RowType = DataControlRowType.DataRow Then       drBurritoPeople = DirectCast(DirectCast(e.Row.DataItem, System.Data.DataRowView).Row, BurritoPeopleRow)       If drBurritoPeople.LikesBurritos Then         e.Row.CssClass = 'BlueRow'      Else         e.Row.CssClass = 'WhiteRow'      End If             End IF  End Sub 

    I’m not quite sure what your implications are about not wanting to iterate through all the data, but this rendering of the white or blue row is occurring at the same time as the data is written to the page, so you’re not losing any performance here.

    EDIT: I guess one potential alternative to this would be to create a third column in your ResultSet that contains a CssClass name that you could declare based on the the LikesBurritos column and you could bind the CssClass to that in your GridView, but this is going to require you to have access to the SQL statement or to intercept your DataBinding process to modify the ResultSet coming down.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 216k
  • Answers 216k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If what you want is capability to take object out… May 12, 2026 at 11:10 pm
  • Editorial Team
    Editorial Team added an answer For read-only controls they are the same. For 2 way… May 12, 2026 at 11:10 pm
  • Editorial Team
    Editorial Team added an answer Just saw it: for ($i=0; count($resultset);$i++) shouldn't it be for… May 12, 2026 at 11:10 pm

Related Questions

I thought I would ask this question to see why many examples and people
I have an ADO .Net Entity Data Model for my database. In this Model
I'm not clear about this.... When having a gridview on the View, is the
I have an ASP.NET page that requires the ability to have users enter multiple

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.