Click here to Skip to main content
14,865,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have populated a dynamic grid view from database with Cell text as ON and OFF. I want that off text should appear in "Red" Colour.
Grid rows are generated as no.of employees and columns are days in a particular month from database.
Posted

1 solution

Using RowDataBound is frequently the best way. Here's a quick example that changes the row color based on the status of a CheckBoxField.

VB
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim cb As CheckBox = CType(e.Row.Cells(1).Controls(0), CheckBox)
            If (cb.Checked = False) Then
                e.Row.BackColor = Drawing.Color.LightYellow
                e.Row.Cells(0).ForeColor = Drawing.Color.Red
            Else
                e.Row.ForeColor = Drawing.Color.Blue
                cb.Enabled = True
            End If
        End If
End Sub




HTH
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900