ASP.NET Gridview conditional formatting


The below will dynamically change the background color of  a gridview called gridview1 when the column data value called SiteScheduleStatus = Scheduled to light green, otherwise the background color of the gridview will be Misty Rose.

Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If DataBinder.Eval(e.Row.DataItem, “SiteScheduleStatus”).ToString() = “Scheduled” Then

e.Row.BackColor = System.Drawing.Color.LightGreen Else e.Row.BackColor = System.Drawing.Color.MistyRose

End If

End If

End Sub

Leave a Reply