.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Change GridView row color based on condition

Posted By: manju     Posted Date: October 29, 2009    Points:2   Category :C#
I want to change a particular row color of gridview based on some condition.

Here in gridview, one column is used for checking.ie, check box.

Now when this value in db is checked, i want to change the color of the row in grid , say gray color.

So how to change the color in gridview based on this condition from db?

How can i do that?

Author: Akhil Raj       [Moderator]      
Posted Date: October 29, 2009     Points: 5   

you can write code for this in rowdatabound event.

Just look at the following article you will get the idea



Author: Amit Mehra             
Posted Date: October 29, 2009     Points: 5   

Hi Manju,

you can use RowDataBound Event of Gridview and depend upon the condition you can change the color like this

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
bool isnewRow = (bool)DataBinder.Eval(e.Row.DataItem, "MyItem");
if ( isnewRow ) e.Row.BackColor = ColorRed;

Please "Mark As Answer " if this post help you.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend