This is an article about filling colors in gridview based on some conditions and values. Also you can check out:
Say for an example: if a gridview has different departments in different locations.
Need to color the gridview values based on the locations and display the top scorers of the winners department wise.
As given below :
Add OnRowDataBound EVENT for the gridview and the find
protected void GvLeaderBorad_OnRowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
Label lblNett = e.Row.FindControl("lbl_Net") as Label;
if (lblNett.Text == Locations.Chennai.ToString())
e.Row.Cells.BackColor = System.Drawing.Color.DarkGreen;
When color code is fetched from label placed inside the row .It will be applied to the entire row.
Thus in code itself when we bind the grid .Provide row color in the label and fetch the color code from it.
Apply the color code(Html hex code ex: #fffff ) to the gridview row.
Hope this article will teach you how to add colors in gridview rows.