How to change grid view row back color based on condition using ASP.NET

In this article I have explained about how to change student row details back color based on his/her mark i.e. if he/she got less than 50 mark in any subject I show that record back color is red. During grid view load time I check the each record all marks using DataBound event.

How to change grid view particular row back color?
You can change grid view row back color based on your condition, in this example application I change row back color if student got less than 50 mark I wrote code inside of "GridView1_DataBound" event. Code like this.
Client side

protected void GridView1_DataBound(object sender, EventArgs e)
for (int i = 0; i < dt.Rows.Count; i++)
GridViewRow row;
row = GridView1.Rows[i];
//Here i check student m1/m2/m3 is less than 50 if more than 50 the row is red color
if ((Convert.ToInt32(dt.Rows[i][2]) < 50) || (Convert.ToInt32(dt.Rows[i][3]) < 50 ) || (Convert.ToInt32(dt.Rows[i][4]) < 50))
row.BackColor = System.Drawing.Color.Red;

Source Code Detail:
Here with I have attached source code to change grid view row back ground color based on condition. Download it and try to change color based on your conditions.
Front End : ASP.NET
Code Behind : C#

I hope this Article is help to you for change grid view row color change.


  • GridView_RowColorChange (42890-29106-GridView_RowclrChange.rar)
  • Comments

    Guest Author: hareesh19 Mar 2012

    this is not working

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: