Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Apr 30, 2007 12:11 AM|LINK
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
' 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
Hope that helps.