No problem. I've repeated the code with comments to help make some sense out of it (if it doesn't, let me know).
' For each row of the GridView RowDataBound is called after the row is created and data is bound to the row.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
' RowDataBound is called for each row, including the header/footer, so need to check that this is a DataRow (if it's
' not, there's no point searching for a checkbox that doesn't exist).
If (e.Row.RowType = DataControlRowType.DataRow) Then
' For any column that's a CheckBoxField, a Checkbox is created in the Controls collection for that Cell of the Row.
' Need to get a reference to that CheckBox to check its properties.
Dim cb As CheckBox = CType(e.Row.Cells(1).Controls(0), CheckBox)
If (cb.Checked = False) Then
' If the CheckBox is not checked, change the background color for the whole row and the text color for only the
' first cell.
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(0).ForeColor = Drawing.Color.Red
Else
' If the CheckBox is checked, change the text color for the whole row and enable the CheckBox (the default
' for a DataRow is disabled).
e.Row.ForeColor = Drawing.Color.Blue
cb.Enabled = True
End If
End If
End Sub
Hope that helps.
Aaron
Don't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so everyone will know you have been helped.
agolden
Star
7893 Points
1060 Posts
Re: Dynamically change color of text in a particular GridView row
Apr 30, 2007 12:11 AM|LINK
Hi JP,
No problem. I've repeated the code with comments to help make some sense out of it (if it doesn't, let me know).
Hope that helps.
Aaron