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 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

Related Questions

I have an ASP.net GridView that spits out three columns of data: ( OrderNumber,
Is it possible to populate asp.net GridView with data and operate on those data
I have a custom gridview control that extends the standard asp.net gridview control. The
I have an ASP.NET dropdown that I've filled via databinding. I have the text
I have my winform application gathering data using databinding. Everything looks fine except that
My current task is an ASP.NET page to display the contents of a data
Assume I have an asp:GridView with some customer information. On that page I also
Is it possible to use a LINQ extension method within an ASP.NET databinding expression?
I have a GridView on ASP.NET web form which I have bound to a
I am getting the following error, Using asp.net and nHibernate. Databinding methods such as

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.