سؤال

I have created a gridview with multiple columns in it. I would like to change the background column of the Teacher Assessment column based on the value in the difference column. Based on my current code below the change of colour is working, but it colours the whole row, I only want to apply it to the Teacher Assessment column.

I would screenshot, but I don't have the rep yet, so I'll try and show it with text:

Target    Teacher Assessment    Difference    (TA column colour)
C+        B-                    1             Green
C+        C-                    -2            Red
C+        C+                    0             Yellow

Here is the code I'm currently using to trigger the change in background colour modified from some code found on the web in an answer to a similar issue:

Protected Sub gdViewAllopen_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim number = DirectCast(e.Row.DataItem, DataRowView)("Difference").ToString()
        Select Case number
            Case 0
                e.Row.BackColor = System.Drawing.Color.Yellow
            Case Is > 0
                e.Row.BackColor = System.Drawing.Color.Green
            Case Is < 0
                e.Row.BackColor = System.Drawing.Color.Red
        End Select
    End If
End Sub

Sussed it out! So easy as well!! Ah well, here it is for the benefit of others. Just add Cells(n) after Row:

e.Row.Cells(2).BackColor = System.Drawing.Color.Yellow

هل كانت مفيدة؟

المحلول

Sussed it out! So easy as well!! Ah well, here it is for the benefit of others. Just add Cells(n) after Row:

e.Row.Cells(2).BackColor = System.Drawing.Color.Yellow

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top